views:

24

answers:

3

How can i use tabs to switch between activities? For example i have some tabs, one of them includes google map and i want each tab to have its own activity with its own .xml file. How can i do it?

A: 

There is a tutorial on the APress Begining android 2 book that does exactly that.

Download the source

Create an android project from existing source in eclipse using the folder from the source code "Fancy\Tab"

After you got your tab thing running, just substitue the activities being loaded into the tabs by what you want. ie a MapActivity.

blindstuff
u mean instead of spec.setContent(R.id.tab1) i shoud write spec.setContent(R.layout.[name]) and FrameLayout in main.xml should be empty? i tried that but got exception
polyakovsky
A: 

iv also tried in this way, but got same exception

        TabHost tabs=(TabHost)findViewById(R.id.tabhost);          
        Intent intent = new Intent().setClass(this, home_scr.class);
        TabHost.TabSpec spec = tabs.newTabSpec("tabHome").setIndicator("H").setContent(intent);
        tabs.addTab(spec);
polyakovsky
A: 

i've solved the problem. in addition to

    TabHost tabs=(TabHost)findViewById(R.id.tabhost);          
    Intent intent = new Intent().setClass(this, home_scr.class);
    TabHost.TabSpec spec = tabs.newTabSpec("tabHome").setIndicator("H").setContent(intent);
    tabs.addTab(spec);

value of "android:id" in xml file with discription of TabHost must be "@android:id/tabhost", also FrameLayout must have "android:id="@android:id/tabcontent", but not another names.

polyakovsky