Reputation: 53
this is my code to show three tabs on top of screen, but its not showing any tabs on the screen,and i don't have the slightest clue why this is happening,can somebody please guide me here is the XML
<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"
android:layout_marginTop="78dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout
android:id="@android:id/tabcontent"
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" />
</LinearLayout>
</TabHost>
and here is the java code
final TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setCurrentTab(1);
final TabHost.TabSpec tab1 = tabHost.newTabSpec("First Tab");
final TabHost.TabSpec tab2 = tabHost.newTabSpec("Second Tab");
final TabHost.TabSpec tab3 = tabHost.newTabSpec("Third Tab");
tab1.setIndicator("Upcoming").setContent(new Intent(this, Upcoming_matches.class));
tab2.setIndicator("Recent").setContent(new Intent(this, Recent_matches.class));
tab3.setIndicator("Fixture").setContent(new Intent(this, Fixtures.class));
tabHost.addTab(tab1);
tabHost.addTab(tab2);
tabHost.addTab(tab3);
tabHost.getTabWidget().getChildAt(0).setLayoutParams(new LinearLayout.LayoutParams((int) Math.ceil((width / 1)), 60));
tabHost.getTabWidget().getChildAt(1).setLayoutParams(new LinearLayout.LayoutParams((int) Math.ceil((width / 3)), 60));
tabHost.getTabWidget().getChildAt(2).setLayoutParams(new LinearLayout.LayoutParams((int) Math.ceil((width / 3)), 60));
Found the answer ,with the help of @Don,it was basically wrong layout,framelayout was below than tabwidget,here is correct XML
<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"
android:layout_marginTop="78dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<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="wrap_content" />
</LinearLayout>
</TabHost>
Upvotes: 0
Views: 828
Reputation: 227
Please change fill_parent to wrap_content in tabconent here is the xml
<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"
android:layout_marginTop="78dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</TabHost>
Upvotes: 2