how to have just one activity with tabhost?



My main_activity is a tabhost. I want when I click tabs go to a activity without tabs on top. main_activity:



public class main_activity extends TabActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Resources ressources = getResources();
TabHost tabHost = getTabHost();

Intent intentEdit = new Intent().setClass(this, EditActivity.class);
TabSpec tabSpecEdit = tabHost
.newTabSpec("Edit")
.setIndicator("", ressources.getDrawable(R.drawable.ic_edit))
.setContent(intentEdit);

Intent intentDelete = new Intent().setClass(this, DeleteActivity.class);
TabSpec tabSpecDelete = tabHost
.newTabSpec("Delete")
.setIndicator("", ressources.getDrawable(R.drawable.ic_delete))
.setContent(intentDelete);

Intent intentAdd = new Intent().setClass(this, AddActivity.class);
TabSpec tabSpecAdd = tabHost
.newTabSpec("Add")
.setIndicator("", ressources.getDrawable(R.drawable.ic_add))
.setContent(intentAdd);

tabHost.addTab(tabSpecEdit);
tabHost.addTab(tabSpecDelete);
tabHost.addTab(tabSpecAdd);
}
}


and one of tabs activities:



public class AddActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add);
}
}


main.xml:



<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://ift.tt/nIICcg"
android:id="@android: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"
android:padding="5dp">
<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"
android:padding="5dp" />
</LinearLayout>
</TabHost>

No comments:

Post a Comment