开发者

TabHost Problem in android

I want Access a single Activity using 2 different tabs.Fo开发者_StackOverflow中文版r Ex I have a single Activity like People and two tabs those names are tab1 and tab2.when i click on tab1 I want to display the people page as my group and when i click on tab2 that same page displayed the show all title.That means I want to Access a single Intent for two tabs In the same way the Information in that Activity is displayed According to Tab.For this purpose what can i do?Give me some suggestions.Thanks in advance.


I don't think I would reuse the same activity for different tabs. Is there a reason you can't use separate activities to represent different views of the same data? The reason I say that is that you would have to write code inside the activity to differentiate between which tab was selected, and I think your code base would be much cleaner if that was inherent in your classes.

I have code in my TabActivity similar to the following for setting activities as the content of my tabs via intents:

    mTabHost = getTabHost();

    // Tab1
    Intent tab1Intent = new Intent(this, ActivityForTab1.class);
    mTabHost.addTab(mTabHost.newTabSpec(TabTag1).setIndicator(TabLabel1).setContent(tab1Intent));     

    // Tab2
    Intent tab2Intent = new Intent(this, ActivityForTab2.class);
    mTabHost.addTab(mTabHost.newTabSpec(TabTag2).setIndicator(TabLabel2).setContent(tab2Intent));     

    mTabHost.setCurrentTab(0);


Do not put activities as the contents of your tabs. Put views as the contents of your tabs. Here is a sample project demonstrating this technique.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜