gpt4 book ai didi

android - java.lang.IllegalStateException ..... 在 tabhost.add(tabspec);

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:34:27 24 4
gpt4 key购买 nike

嗨 guyzz 我有 TabActivity 如下简单的代码

public class TabhostActivity extends Activity{
TabHost host;

public class TabhostActivity extends Activity{
TabHost host;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);

setContentView(R.layout.tablayout);

host = (TabHost) findViewById(R.id.mytabhost);

host.setup();
Intent intent = new Intent(getApplicationContext(), RatingBarActivity.class);
TabHost.TabSpec spec = host.newTabSpec("positions").setIndicator("Positions",getResources().getDrawable(R.drawable.add)).setContent(intent);

host.addTab(spec);
host.setCurrentTab(0);

}

并且有一个简单的选项卡布局

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TabHost
android:id="@+id/mytabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">

<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp">

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#FF0000">

</FrameLayout>

<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<TabWidget
android:layout_marginLeft="5dp"
android:id="@android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tabStripEnabled="true" >
</TabWidget>
</HorizontalScrollView>
</LinearLayout>
</TabHost>

</LinearLayout>

所以请帮我看看代码哪里出错了??我有异常(exception)

02-23 14:09:47.920: E/AndroidRuntime(1000): Caused by: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?

最佳答案

你正在扩展Activity类,尝试扩展TabActivity

如果您想使用 Activity 类,请使用以下内容:

host = (TabHost) findViewById(R.id.tabhost); //here tabHost will be your Tabhost
LocalActivityManager mLocalActivityManager = new LocalActivityManager(mActivity, false);
mLocalActivityManager.dispatchCreate(state); // state will be bundle your activity state which you get in onCreate
tabHost.setup(mLocalActivityManager);

关于android - java.lang.IllegalStateException ..... 在 tabhost.add(tabspec);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9409735/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com