I am trying to create a tab view with will switch to a different content view by Id. Here is my tab activity
:
public class TabViews extends TabA
Your xml should have something like ,
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<FrameLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="test"/>
<TextView android:id="@+id/view2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="test"/>
<TextView android:id="@+id/view3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="test"/>
</FrameLayout>
</TabHost>
examples: http://www.androidhive.info/2011/08/android-tab-layout-tutorial/ http://www.codeproject.com/Articles/107693/Tabbed-Applications-in-Android
you should have TabHost
and TabWidget
in your xml layout, take a look at the Tab Layout example.
you need add tabwidget in the xml.... Checkout, this is how to use tab widget :
tabscroll.xml
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</HorizontalScrollView>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
public class Tabs5 extends TabActivity implements TabHost.TabContentFactory {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs_scroll);
final TabHost tabHost = getTabHost();
for (int i=1; i <= 30; i++) {
String name = "Tab " + i;
tabHost.addTab(tabHost.newTabSpec(name)
.setIndicator(name)
.setContent(this));
}
}
/** {@inheritDoc} */
public View createTabContent(String tag) {
final TextView tv = new TextView(this);
tv.setText("Content for tab with tag " + tag);
return tv;
}
}
Courtesy : http://developer.android.com/resources/samples/ApiDemos/res/layout/tabs_scroll.html AND http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/Tabs5.html