Calling Baseadapter's Notifydatasetchanged() Inside Customadapter Not Refreshing Listview
I have ArrayList data which is populated on the ListView using a CustomAdapter. I've implemented View.OnClickListener in the CustomAdapter class and clicking a butt
Solution 1:
I had a similar issue some time ago, I fixed it extending ArrayAdapter<MyObject>
instead of BaseAdapter
and overriding some methods:
publicclassCustomAdapterextendsArrayAdapter<MyObject> {
private List<MyObject> list = newArrayList<MyObject>();
publicCustomAdapter(Context context, int resource) {
super(context, resource);
}
@Overridepublicvoidadd(MyObject obj) {
this.list.add(obj);
super.add(obj);
}
@Overridepublicvoidremove(MyObject obj) {
inti= getPosition(obj);
if(i >= 0)
list.remove(i);
super.remove(obj);
}
@Overridepublicvoidclear() {
this.list.clear();
super.clear();
}
@Overridepublic MyObject getItem(int position) {
returnthis.list.get(position);
}
@OverridepublicintgetPosition(MyObject obj) {
for(inti=0; i < list.size(); i++) {
if(list.get(i).equals(obj))
return i;
}
return -1;
}}
Then call these methods instead of calling directly methods of your List.
Post a Comment for "Calling Baseadapter's Notifydatasetchanged() Inside Customadapter Not Refreshing Listview"