Reputation: 272
I follow tutorial found on internet, but it seems that doesn't work...
I get Tab 1 always opened, that is okay, but I don't see TABS menu up...
Here is my code:
Main2Activity:
public class Main2Activity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
// create the TabHost that will contain the Tabs
TabHost tabs=(TabHost)findViewById(R.id.tabhost);
tabs.setup();
TabHost.TabSpec spec=tabs.newTabSpec("tag1");
spec.setContent(R.id.tab1);
spec.setIndicator("Analog Clock");
tabs.addTab(spec);
spec=tabs.newTabSpec("tag2");
spec.setContent(R.id.tab2);
spec.setIndicator("DigitalClock");
tabs.addTab(spec);
spec=tabs.newTabSpec("tag3");
spec.setContent(R.id.tab3);
spec.setIndicator("Button");
tabs.addTab(spec);
}
Content_main2.xml:
<?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">
<AnalogClock android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<DigitalClock android:id="@+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<Button android:id="@+id/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Do Nothing"/>
</FrameLayout>
</LinearLayout>
</TabHost>
This is how it looks when i run it
Upvotes: 1
Views: 240
Reputation: 505
you can use seperate activity
for each tab
. as said by "intelliJ". create seperate activity
and seperate xml
file for each tab
and then add your analog digital and button in each activity respectively. say in activity1
add analog
and in activity2
add digital
and so on.
Upvotes: 0
Reputation: 272
I solved it with:
setContentView(R.layout.content_main2);
I was calling activity_main2, but don't know why when I call activity_main2 don't get content_main2.
I have in Activity_main2.xml:
<include layout="@layout/content_main2" />
Does anyone know why?
Upvotes: 1