问题描述
我的code:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
// LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
tabHost.setup();
TabSpec tabSpecCheckIn = tabHost.newTabSpec(getResources().getText(R.string.button_check_in).toString());
tabSpecCheckIn.setIndicator(getResources().getText(R.string.button_check_in).toString(), getResources().getDrawable(android.R.drawable.star_off));
tabSpecCheckIn.setContent(R.id.check_in);
tabHost.addTab(tabSpecCheckIn);
TabSpec tabSpecReview = tabHost.newTabSpec(getResources().getText(R.string.button_review).toString());
tabSpecReview.setIndicator(getResources().getText(R.string.button_review).toString(), getResources().getDrawable(android.R.drawable.star_off));
tabSpecReview.setContent(R.id.review);
tabHost.addTab(tabSpecReview);
TabSpec tabSpecMyCircles = tabHost.newTabSpec(getResources().getText(R.string.button_my_circles).toString());
tabSpecMyCircles.setIndicator(getResources().getText(R.string.button_my_circles).toString(), getResources().getDrawable(android.R.drawable.star_off));
tabSpecMyCircles.setContent(R.id.my_circle);
tabHost.addTab(tabSpecMyCircles);
TabSpec tabSpecMySettings = tabHost.newTabSpec(getResources().getText(R.string.button_settings).toString());
tabSpecMySettings.setIndicator(getResources().getText(R.string.button_settings).toString(), getResources().getDrawable(android.R.drawable.star_off));
tabSpecMySettings.setContent(new Intent(this,CheckInActivity.class));
tabHost.addTab(tabSpecMySettings);
tabHost.setCurrentTab(0);
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost android:id="@+id/tabhost"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TabWidget android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@android:id/tabs"
android:layout_gravity="bottom" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:paddingTop="65px">
<LinearLayout android:id="@+id/check_in"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="5px">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="date"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout android:id="@+id/review"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="5px">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="lieu"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout android:id="@+id/my_circle"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="5px">
</LinearLayout>
<LinearLayout android:id="@+id/setting"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="5px">
</LinearLayout>
</FrameLayout>
</TabHost>
</LinearLayout>
当我点击设定的按钮,exctption:
When I click the button of Setting, exctption:
你忘了叫'公共无效设置(LocalActivityManager的ActivityGroup)
谁能帮我。我尝试从 TabActiviy
扩展或的ActivityGroup
还有一些例外!
我想提出Tabhost的按键在底部,当我按一下按钮调用不同的活动!
Who Can help me. I try to extends from TabActiviy
or ActivityGroup
still other exceptions!!!
I want to put the buttons of Tabhost at bottom and when I click the button invoke different Activities!
推荐答案
您需要从活动到的ActivityGroup改变MainActivity的基类,如下所示:
you need change MainActivity's base class from Activity to ActivityGroup, as follows:
public class MainActivity extends ActivityGroup {
...
}
的ActivityGroup将LocalActivityManager实例的照顾。所以,你不需要创建它。基类变更后,只需要调用基类中定义得到该实例getLocalActivityManager()函数。呼叫tabHost的设置功能是这样的:
ActivityGroup will take care of an instance of LocalActivityManager. So you don't need to create it. After the base class is changed, just call getLocalActivityManager() function defined in the base class to get that instance. Call tabHost's setup function like this:
tabHost.setup(this.getLocalActivityManager());
这篇关于Android的例外:你忘了叫'公共无效设置(LocalActivityManager的ActivityGroup)“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!