Using java Syntax Highlighting
- public class TestActivity extends TabActivity implements TabHost.TabContentFactory
- {
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- TabHost tabHost = getTabHost();
- tabHost.addTab(tabHost.newTabSpec("tab1")
- .setIndicator("Bingo", getResources().getDrawable(android.R.drawable.star_big_on))
- .setContent(this));
- tabHost.addTab(tabHost.newTabSpec("tab2")
- .setIndicator("Bongo", getResources().getDrawable(android.R.drawable.star_big_on))
- .setContent(this));
- }
- public View createTabContent(String tag)
- {
- if(tag.equals("tab1"))
- return View.inflate(this, R.layout.tab1, null);
- else if(tag.equals("tab2"))
- return View.inflate(this, R.layout.tab2, null);
- else
- return null;
- }
- }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
My question is, what exactly is the point of this approach? From the createTabContent() method, you return a View, but how exactly do then get into it and register action listeners and so forth? How do you setup and manage the view and plumb in the functionality?
My preference so far has been to use Intents which start a new activity in each tab. This works well in many ways, since each activity is a discrete component which is responsible for setting itself up and managing state etc. The issue I am having then is that the activities are too discrete - when they need to communicate between each other there are some real complications. These, I have more or less managed to cope with using Handlers. My latest issue with this approach is that the root class that extends TabActivity must reinitialise each tab when you rotate the screen. This causes the dialog management mechanism to fail. If a tab is showing a dialog and you rotate the screen, the dialog is not reinstated in the new tab that replaces it after rotation.
So I have been looking into alternative ways to set up tabs, which brings me to the code above....
Anyone got any links? Any example code? I have been searching for a few days now and cannot find any authoritative tutorial or resource which takes you through the different mechanisms for using Tabs and it's starting to look like I will have to do like others have and roll my own which seems.... drastic...



