本文介绍了Android 异常:您是否忘记调用“public void setup (LocalActivityManager activityGroup)"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我的代码:

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:

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

谁能帮帮我.我尝试从 TabActiviyActivityGroup 扩展还有其他例外!!!
我想把 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!

推荐答案

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

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 异常:您是否忘记调用“public void setup (LocalActivityManager activityGroup)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 20:11