4
现在我在我的应用程序tabhost中使用单个活动和单独的视图。在TabHost中更改视图(一个活动,多个视图)
选项卡活动:
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabs = (TabHost) findViewById(R.id.tabhost);
tabs.setup();
TabHost.TabSpec spec = tabs.newTabSpec(TAB_HOTELS);
spec.setContent(R.id.tab1);
spec.setIndicator("Hotels");
tabs.addTab(spec);
spec = tabs.newTabSpec(TAB_LAST_MINUTE);
spec.setContent(R.id.tab2);
spec.setIndicator("Last Minute");
tabs.addTab(spec);
布局
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/tab1"
android:orientation="vertical">
<ListView android:id="@+id/listaLocalita"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/tab2"
android:orientation="vertical" android:paddingTop="60px">
<TextView android:layout_width="fill_parent"
android:layout_height="100px" android:text="This is tab 2"
android:id="@+id/txt2" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
,事情是我使用的一个一级深度相当不错,只要工作。不幸的是,现在我需要使其中一个选项卡工作如下:
Tab加载ListView与城市列表,用户点击城市名称,选项卡的内容被替换为酒店列表,用户选择一家酒店,总是在同一个标签页中,酒店的信息被加载。
我该如何实现这种情况? LayoutInflater?
在此先感谢。
你有没有想过这个?我正在寻找类似的东西。 – 2011-11-16 20:53:02
只看[本例](http://ericharlow.blogspot.in/2010/09/experience-multiple-android-activities.html)。希望它会帮助你。 – 2012-02-04 04:30:32