Using tabs and MapActivitys (Android)
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?
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.
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);
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.
精彩评论