I have a listview which populated with arraylist. However, anytime I use the pull to refresh, the data in the listview gets duplication even though I clear the arraylist before populating. This is my arraylist
List<TimeItems> myList = new ArrayList<TimeItems>();
and this is how I am populating the adapter
for (int in = 0; in <= video.size() - 1; in ++) {
String a = vDancers.get(in);
String b = video.get(in);
String c = vName.get(in);
TimeLineItems item = new TimeLineItems(a,b,c);
myList.add(item);
}
Collections.sort(myList);
you = new MyVideoAdapter(getActivity(), myList,nLikes,nComments,nRepost);
//you.notifyDataSetChanged();
listView.setAdapter(you);
and this is how I am clearing myList on pull-to-refresh
listView.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
you = null;
nComments.clear();
nRepost.clear();
nRepost.clear();
myList.clear();
parseFetch();
listView.onRefreshComplete();
}
}, 5000);
}
});
where you is my BaseAdapter and parseFetch() is my method to load network data. How do I completely clear myList before refresh so I don't have duplicated in my listview? Thanks for your help
I got it. I wasn't also clearing the other arrays I was using to populate myList. After logging the various stages, I realised these arrays were duplicated so I just needed to clear them as well. This is the final work.Thanks @Lavkush2oct and @Vesko for the help.