Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Exception: Did you forget to call 'public void setup (LocalActivityManager activityGroup)'

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>

When I click the button of Setting, exctption:

Did you forget to call 'public void setup (LocalActivityManager activityGroup)'

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!

like image 969
ZHAO Xiaojian Avatar asked Jul 17 '10 17:07

ZHAO Xiaojian


2 Answers

you need change MainActivity's base class from Activity to ActivityGroup, as follows:

  public class MainActivity extends ActivityGroup {
  ...
  }

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());
like image 64
douyw Avatar answered Oct 15 '22 12:10

douyw


Instead of setup():

LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
setup(mLocalActivityManager);
like image 34
Sameer Segal Avatar answered Oct 15 '22 11:10

Sameer Segal