How To Call Listview Adapter From Another Activity For Refresh - Notifydatasetchanged()
I want to call a listview adapter from another activies after insert record to sqllite db. I cant call the adapter.notifyDataSetChanged() method. What is the best way to do it. pub
Solution 1:
Just
After finish()
Current Activity, Call adapter.notifyDataSetChanged()
from onActivityResult()
in previous Activity (As I assumes your Listview in this previous Activity).
Also start your Current Activity from Previous Activity using startActivityForResult();
Or if you have reference of List Adapter in this Activity, then using that reference call adapter.notifyDataSetChanged()
. (But I think its not a good practice)
Solution 2:
The better option would be re-loading your ListView
with new data inside onResume()
of your Activity where you have ListView. There is no need to call notifyDataSetChanged()
from another class as you don't have your List visible in your another Activity.
@OverrideprotectedvoidonResume() {
super.onResume();
//fill your Collection with new data// setAdapter or notify your adapter
}
Post a Comment for "How To Call Listview Adapter From Another Activity For Refresh - Notifydatasetchanged()"