Android异常:您是否忘记调用'public void setup(LocalActivityManager activityGroup)'

时间:2010-07-17 17:19:54

标签: android exception android-tabhost

mycode的:

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:

  

您是否忘记调用'public void setup(LocalActivityManager activityGroup)'

谁能帮助我。我尝试从TabActiviyActivityGroup延伸到其他例外!!!
我想把Tabhost的按钮放在底部,当我点击按钮调用不同的活动时!

2 个答案:

答案 0 :(得分:38)

您需要将MainActivity的基类从Activity更改为ActivityGroup,如下所示:

  public class MainActivity extends ActivityGroup {
  ...
  }

ActivityGroup将处理LocalActivityManager的一个实例。所以你不需要创建它。更改基类后,只需调用基类中定义的getLocalActivityManager()函数即可获取该实例。调用tabHost的设置功能如下:

  tabHost.setup(this.getLocalActivityManager());

答案 1 :(得分:3)

而不是setup():

LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
setup(mLocalActivityManager);