tags:

views:

51

answers:

1

Hello all, am not too experienced in android and i am just using the TabActivity, so please bear with me. i keep seeing post about not using activites in Tabhost but views. and am not sure which is which and if thats the reason of my latest headache? i have a code with 4 tabs like this:

 // Category TabActivity class
    tab.setContent(new Intent(this, Mylist.class));
    tab1.setContent(new Intent(this, Mylist.class));
    tab2.setContent(new Intent(this, Mylist.class));

and each tab is showing the result of a method in the Mylist Activity.

  1. is that using an activity in a tab or displaying a view? whats the difference?.

  2. i have a context menu on an item selected in the Mylist Activity which updates the list. how can i reflect the changes in the list back to the tab in other to display that particular method in the Mylist class, that was set as the tabs content. obviously this will change if i updated or deleted an item from the list when the tab is shown. i think its possible with onResume(), but don't know what to call there or is there any better way?

    in the Mylist class, i have tried this little piece of code to restart the TabActivity:

    myAdapter.deleteItem(id);

           fillData(); // 
        Intent refereshCategory = new Intent(this, Category.class);
          startActivity(refereshCategory);
    

its restarting the activity after the item have been deleted, but how can i only show the tab whose view was in focus when it restarts and i don't want fillData() method to be shown as it does not have to do with the tabs. i hope i made myself clear enough. Thanks

Any help will be greatly appreciated. Thanks for your time.

A: 

With tab.setContent(new Intent(this, Mylist.class)); You are telling the application to display a new MyList Activity in that tab.

I'm not sure of the activity lifecycle for tabbed activities but I think it is safe to assume they follow the same standards as regular activities. onResume is called every time the activity shown (which would include being switched from another tab's activity to this activity). So any kind of updating you want to do to the list every time it is shown should go here and not in onCreate(Bundle savedInstanceState)

To create any kind of Android application you should become familiar with the Component Lifecycle

Austyn Mahoney
ok, thanks. so that means its not displaying a view. how do i get to display a view then. and also, do i just call the requested method again in onResume?. it doesn't seem to work or do i need to write that little piece of code again in onResume for it to get a fresh display? sorry for all the questions.. Thanks
sparrow
i have edited my question.. please see above
sparrow