Monday, 9 September 2013

ActionBarActivity with TabHost

ActionBarActivity with TabHost

I am developing an app, with minimum sdk level 7 and that's why I use
support library and ActionBarActivity to have a proper ActionBar, but also
the layout of my page contains four tabs on the bottom of the activity,
and as i already extend ActionBarActivity, I cannot extend TabActivity.
The problem is when I write
public class HomePageActivity extends ActionBarActivity {
private TabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_homepage);
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
TabHost.TabSpec tab1 = mTabHost.newTabSpec("TAB1");
tab1.setIndicator("TAB 1");
Intent popularContentIntent = new Intent().setClass(this,
GuideActivity.class);
tab1.setContent(popularContentIntent);
mTabHost.addTab(tab1);
I get the error "Did you forget to call 'public void
setup(LocalActivityManager activityGroup)?'" at the line when I trying to
add tab to the tabhost. If I try to set the id of the view in the
tab.setContent(..) like tab.setContent(R.id.tab1) and have a view in the
xml with the id tab1, I get the error that the view with such a number
cannot be found.
My layout:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
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"
android:layout_above="@android:id/tabs"
android:layout_alignParentTop="true" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
</Button>
</TabWidget>
</RelativeLayout>
Is it possible somehow to have layout with tabs and actionbar at the same
time? What I do wrong? What could be other alternatives? Thanks a lot!

No comments:

Post a Comment