Refresh Listview Created From An Arraylist After Delete Operation
I have seen too many questions about refreshin a listview and I have tried every solution on the topics but none worked for me. have tried notifysetdatachange(), invalidateviews, r
Solution 1:
Your should use these syntax for achieving it
((YourAdaptor)Listview.getAdaptor()).notifyDataSetChange();
Solution 2:
Try this code and for your adapter class,
// query fire on your deletion operation
mArrayList.remove(position);
notifyDataSetChanged();
Solution 3:
From my experience, it is strange the behaviour of the listview to refresh it. I always do the same to refresh listView without problems:
- Use custom Adapter which extends from BaseAdapter
- Use ArrayList<> structure data into the adapter. If you have your data in a database SQLiteDatabase, I recomend to put the data you need int that list in an ArrayList and pass it to the adapter. I can't do the same with CursorAdapter :(
- Make your ArrayList and your Adapter public static in your Activity if you plan to modify the data outside the Activity and want to update the list.
- When you modify or remove any info from your data (if you do it directly on your database, duplicate the same into the ArrayList), use the public static reference of the Adapter of your Activity to call his method notifyDataSetChanged()
Post a Comment for "Refresh Listview Created From An Arraylist After Delete Operation"