开发者

call tab host from other activity

I m new to android. Can you tell how can i call TabActivity from my other ac开发者_C百科tivity outside of TabActivity. Which is actually a menu. I want to have TabHost after selecting one of the menu option. Thanks


If i understand you right,you just need to add tabhost to your new activity.Something like this :

Intent intent = new Intent(MainClass.this, TabActivity.class);
startActivity(intent);

and the TabActivity.class :

Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, Collection.class);
        spec = tabHost.newTabSpec("collection").setIndicator("Collection",
                          res.getDrawable(R.drawable.ic_tab_collection))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, Store.class);
        spec = tabHost.newTabSpec("store").setIndicator("Store",
                res.getDrawable(R.drawable.ic_tab_store))
            .setContent(intent);
        tabHost.addTab(spec);

Something like this.Hope this helps

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜