开发者

Help with the tab tutorial

Hey I am new to android development and most programing in general other then 2 semesters of C++. But my question revolves around this tutorial http://developer.android.com/resources/tutorials/views/hello-tabwidget.html I was able to follow how to开发者_JAVA百科 write the previous ones but when it comes to this one I am having trouble. My question is, what does it mean when it says to create a separate activity for each tab and how do I go about that?


You simply need to create two or more activities via the normal means: create a class that extends Activity, declare them in the manifest, ect. Then create your tab activity that extends the TabActivity. From there this code snip highlights the high points (note that I assume two activities exist called ActivityA and ActivityB)...

public class MyTabActivity extends TabActivity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_tab_layout);

        final Resources res     = getResources(); 
        final TabHost   tabHost = getTabHost();  

        TabHost.TabSpec spec;  
        Intent          intent;  

        /* Add tab A */
        intent = new Intent().setClass(this, ActivityA.class);
        spec   = tabHost.newTabSpec("tab_a")
                        .setIndicator("Tab A", res.getDrawable(R.drawable.ic_tab_a))
                        .setContent(intent);
        tabHost.addTab(spec);

        /* Add tab B */
        intent = new Intent().setClass(this, ActivityB.class);
        spec   = tabHost.newTabSpec("tab_b")
                        .setIndicator("Tab B", res.getDrawable(R.drawable.ic_tab_b))
                        .setContent(intent);
        tabHost.addTab(spec);
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜