Hi i have problem with displaying ListView in android 8 .
In android 6 it s working correctly :
https://drive.google.com/file/d/1qV1igHXBD0YiYUC73T2rNqreVWPE6893/view?usp=sharing
.
But in android 8 it s empty and i dont know why.
Can someone help me.
!
This is my code :
**public class CustomView extends ArrayAdapter<
String>** {
List<String> date;
List<String> description;
List<Integer> image;
Activity context;
public CustomView( Activity context, List<Integer> image,List<String> date, List<String> description) {
super(context, R.layout.urlop,date);
this.context=context;
this.image=image;
this.date=date;
this.description=description;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
ViewHolder vv=null;
if(convertView==null)
{
LayoutInflater layoutInflater=context.getLayoutInflater();
convertView=layoutInflater.inflate(R.layout.urlop,null,true);
vv=new ViewHolder(convertView);
convertView.setTag(vv);
}else {
vv= (ViewHolder) convertView.getTag();
}
vv.img.setImageResource(image.get(position));
vv.dd.setText(date.get(position));
vv.desc.setText(description.get(position));
return convertView;
}
class ViewHolder{
TextView dd;
TextView desc;
ImageView img;
ViewHolder(View v){
dd=(TextView) v.findViewById(R.id.data);
desc=(TextView) v.findViewById(R.id.description);
img=(ImageView) v.findViewById(R.id.imageView);
}
}
}
------------------------------------------------------------------------------------------------------
**public class Allurlop extends AppCompatActivity** {
List<String>bodyy1=new ArrayList<>();
String id;
JsonAPi jsonAPi;
TextView ed;
TextView ts;
ListView ll;
ArrayAdapter aa;
List<String>data=new ArrayList<>() ;
List<String> description=new ArrayList<>() ;;
List<Integer> image=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_allurlop);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Retrofit build = new Retrofit.Builder()
.baseUrl("http://192.168.0.4:8080")
.addConverterFactory(GsonConverterFactory.create())
.build();
jsonAPi = build.create(JsonAPi.class);
ll=(ListView)findViewById(R.id.rc);
CustomView customView=new CustomView(this,image,description,data);
ll.setAdapter(customView);
Bundle extras = getIntent().getExtras();
id= extras.getString("id");
lista();
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
public void lista(){
Call<List<Urlop>> listCall = jsonAPi.geTallUsers();
listCall.enqueue(new Callback<List<Urlop>>() {
@Override
public void onResponse(Call<List<Urlop>> call, Response<List<Urlop>> response) {
List<Urlop> body = response.body();
String daty="";
String descs="";
int im=0;
for(Urlop bb:body){
if(id.equals(String.valueOf(bb.getId()))) {
daty = "Od: " + bb.getStart() + " - do: " + bb.getEnd();
descs = "";
data.add(daty + "\n" + bb.getDescription()+"\n"+" Zastępstwo: "+bb.getZastepstwo());
if (bb.getStatus() == 0) {
im = R.drawable.czeka;
descs = "Czeka na akceptację przełożonego";
} else if (bb.getStatus() == 2) {
im = R.drawable.odrzucony;
descs = "Odrzucone przez przełożonego";
} else {
im = R.drawable.zakceptowany;
descs = "Zatwierdzony przez przełożonego";
}
description.add(descs);
image.add(im);
}
}}
@Override
public void onFailure(Call<List<Urlop>> call, Throwable t) {
Toast.makeText(getApplicationContext(),t.getMessage(),Toast.LENGTH_LONG).show();
}
});
}
-------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".Allurlop"
tools:showIn="@layout/activity_allurlop">
<TextView
android:id="@+id/ts"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/rc"
style="@android:style/Widget.DeviceDefault.ExpandableListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible" />
</RelativeLayout>
----------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView"
android:layout_width="96dp"
android:layout_height="89dp" />
<TextView
android:id="@+id/data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/imageView"
android:fontFamily="sans-serif-black"
android:textColor="@color/colorPrimaryDark"
android:textSize="18sp" />
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/imageView"
android:layout_marginTop="30sp"/>
</RelativeLayout>
</LinearLayout>
------------------------------------------------------------------------------------------------
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.retrofit"
minSdkVersion 21
targetSdkVersion 28
versionCode 2
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
testImplementation '
junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation files('src/androidTest/java/javax.servlet.jar')
implementation 'com.android.support:recyclerview-v7:28.0.0'
}