Skip to content

Instantly share code, notes, and snippets.

@jpt1122
Created April 17, 2016 07:52
Show Gist options
  • Save jpt1122/f724ceeb23c1c76b58aef54ea94b8887 to your computer and use it in GitHub Desktop.
Save jpt1122/f724ceeb23c1c76b58aef54ea94b8887 to your computer and use it in GitHub Desktop.
How to add tab layout without letting the activity to extend TabActivity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical"
android:weightSum="1" >
<TabHost
android:id="@+id/tabhostscreen_tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="@+id/tabhostscreen_relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@android:id/tabs"
android:layout_alignParentTop="true" >
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
</TabWidget>
</RelativeLayout>
</TabHost>
</LinearLayout>
public class Rest_Tab extends Rest_HeaderFooter {
TabHost tabHost;
LocalActivityManager mLocalActivityManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.rest_tab);
ViewGroup vg = (ViewGroup) findViewById(R.id.lldata);
ViewGroup.inflate(getApplicationContext(), R.layout.rest_tab, vg);
this.tabHost = (TabHost) findViewById(R.id.tabhostscreen_tabhost);
mLocalActivityManager = new LocalActivityManager(this, false);
tabHost.setup(mLocalActivityManager);
mLocalActivityManager.dispatchCreate(savedInstanceState);
// for photos..
TabSpec photosSpec = tabHost.newTabSpec("Amenities");
photosSpec.setIndicator("Amenities", null);
Intent photoIntent = new Intent(this, RestSystem1Activity.class);
photoIntent.putExtra("User", "R");
photosSpec.setContent(photoIntent);
// for songs..
TabSpec songsSpec = tabHost.newTabSpec("Gallery");
songsSpec.setIndicator("Gallery", null);
Intent songsIntent = new Intent(this, Rest_Gallary.class);
songsSpec.setContent(songsIntent);
// for videos..
TabSpec videosSpec = tabHost.newTabSpec("AboutUs");
videosSpec.setIndicator("AboutUs", null);
Intent videosIntent = new Intent(this, Rest_Branch.class);
videosSpec.setContent(videosIntent);
tabHost.addTab(photosSpec); // Adding photos tab
tabHost.addTab(songsSpec); // Adding songs tab
tabHost.addTab(videosSpec);
}
@Override
protected void onPause() {
super.onPause();
mLocalActivityManager.dispatchPause(isFinishing()); // you have to
// manually dispatch
// the pause msg
}
@Override
protected void onResume() {
super.onResume();
mLocalActivityManager.dispatchResume(); // you have to manually dispatch
// the resume msg
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment