I have an android tabbed application and inside one of my tabs is an activity that has a ListView of favorite items.
The user can add or remove items in an activity that is further down the flow. The problem is, I can't reload the list when user comes back. onResume does not get called so I dont know when I should reload the list. EDIT This is how I'm starting the subseque开发者_Go百科nt activities.Intent i = new Intent(this, CargasCadastro.class);
// Create the view using Group's LocalActivityManager
Window win = CargasGroup.group.getLocalActivityManager().startActivity("CargasCadastro",i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
View guialayout = win.getDecorView();
// Again, replace the view
CargasGroup.group.replaceView(guialayout);
onTabChanged wont work because the the activity that contains the list is not a TabActivity, and my problem is coming back from a subsequent activity, not a parallel one. Thanks for the suggestions.
There are multiple ways to implement a Tab Activity in android.
Although you should receive onResume if you have different activities for handling different tabs, you can use onTabChanged() method to keep track of the tab user has selected and perform task accordingly.
In the activity that contains the listview override the onTabChanged() and call adapter.notifydatasetchanged()
or listView1.setAdapter(adapter)
to refresh the listview.
The way I got it working.
Created a static public instance of the activity inside itself (almost like a singleton).
public static MyActivity instance;
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
instance = this;
...
and a public method that reloads the data and refreshes the listview. Then the down-the-flux activity, accesses this instance and calls the method.
Its dirty, but works.
Will accept my own answer as long as it gets upvoted (hoping for a cleaner solution).
I suggest you to change ure current activity to ActivityGroup
精彩评论