I am setting a custom base adapter for a array list But the getView() method of the my adapter is not called. I tried many solutions but non of them worked for me. I am calling setAdapter() function from postExecute of Aynctask
@Override
protected void onPostExecute(ArrayList<Object> objects) {
MyListAdapter myAdapter = new MyListAdapter(MySearchList.this,objects);
ListView lv = findViewById(R.id.MyList);
lv.setAdapter(myAdapter);
Log.d("done", "onPostExecute: Done");
}
And my custom Adapter class is
public class MyListAdapter extends BaseAdapter {
private final ArrayList<Object> myList;
private final Activity context;
private LayoutInflater inflater;
public MyListAdapter(Activity context , ArrayList<Object> myList) {
this.myList = myList;
inflater = LayoutInflater.from(context);
this.context = context;
Log.d("constructor", String.valueOf(myList.size()));
}
@Override
public int getCount() {
Log.d("", "getCount: ");
return myList.size();
}
@Override
public Object getItem(int position) {
return myList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View rowView;
Log.e("adapting", myList.get(position).toString() );
if (myList.get(position) instanceof wordDefination){
Log.e("adapting", myList.get(position).toString() );
rowView = inflater.inflate(R.layout.word_meaning_single,null,true);
}
else{
rowView = inflater.inflate(R.layout.word_meaning_single,null,true);
}
return rowView;
}
@Override
public int getViewTypeCount() {
return 2;
}
constructor of adapter is calling but the getView() method is not
update : i also tried to use ArrayAdapter instead of BaseAdapter But not working
public class MyListAdapter extends ArrayAdapter<Object> {
private final ArrayList<Object> myList;
private final Activity context;
private LayoutInflater inflater;
public MyListAdapter(Activity context , ArrayList<Object> myList) {
super(context,R.layout.word_meaning_single,myList);
this.myList = myList;
inflater = LayoutInflater.from(context);
this.context = context;
Log.d("constructor", String.valueOf(myList.size()));
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View rowView;
Log.e("adapting", myList.get(position).toString() );
if (myList.get(position) instanceof wordDefination){
Log.e("adapting", myList.get(position).toString() );
rowView = inflater.inflate(R.layout.word_meaning_single,null,true);
}
else{
rowView = inflater.inflate(R.layout.word_meaning_single,null,true);
}
return rowView;
}
}