0
我試圖做一個主菜單,其中包含一個FragmentTabHost
其中包含兩個Intents
打開一些Activities
,但它會一直崩潰,當我嘗試運行它。FragmentTabHost活動意圖崩潰
的XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp" />
</RelativeLayout>
而對於MainMenu的
package com.example.callfinder;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.widget.TabHost.TabSpec;
public class MainMenu extends FragmentActivity {
private FragmentTabHost tabHost;
Intent inCall, inText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
tabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
tabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
inCall = new Intent("com.example.callfinder.FINDCALLS");
TabSpec specCall = tabHost.newTabSpec("calls");
specCall.setIndicator("Calls").setContent(inCall);
tabHost.addTab(specCall);
inText = new Intent("com.example.callfinder.FINDTEXTS");
TabSpec specText = tabHost.newTabSpec("text");
specText.setIndicator("Texts").setContent(inText);
tabHost.addTab(specText);
tabHost.setCurrentTab(0);
}
}
代碼和錯誤日誌
05-28 00:55:08.634: E/AndroidRuntime(28026): FATAL EXCEPTION: main
05-28 00:55:08.634: E/AndroidRuntime(28026): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.callfinder/com.example.callfinder.MainMenu}: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
05-28 00:55:08.634: E/AndroidRuntime(28026): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
05-28 00:55:08.634: E/AndroidRuntime(28026): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2356)
05-28 00:55:08.634: E/AndroidRuntime(28026): at android.app.ActivityThread.access$600(ActivityThread.java:150)
05-28 00:55:08.634: E/AndroidRuntime(28026): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
05-28 00:55:08.634: E/AndroidRuntime(28026): at android.os.Handler.dispatchMessage(Handler.java:99)
05-28 00:55:08.634: E/AndroidRuntime(28026): at android.os.Looper.loop(Looper.java:137)
05-28 00:55:08.634: E/AndroidRuntime(28026): at android.app.ActivityThread.main(ActivityThread.java:5195)
05-28 00:55:08.634: E/AndroidRuntime(28026): at java.lang.reflect.Method.invokeNative(Native Method)
05-28 00:55:08.634: E/AndroidRuntime(28026): at java.lang.reflect.Method.invoke(Method.java:511)
05-28 00:55:08.634: E/AndroidRuntime(28026): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
05-28 00:55:08.634: E/AndroidRuntime(28026): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
05-28 00:55:08.634: E/AndroidRuntime(28026): at dalvik.system.NativeStart.main(Native Method)
05-28 00:55:08.634: E/AndroidRuntime(28026): Caused by: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
05-28 00:55:08.634: E/AndroidRuntime(28026): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:747)
05-28 00:55:08.634: E/AndroidRuntime(28026): at android.widget.TabHost.setCurrentTab(TabHost.java:413)
05-28 00:55:08.634: E/AndroidRuntime(28026): at android.widget.TabHost.addTab(TabHost.java:240)
05-28 00:55:08.634: E/AndroidRuntime(28026): at com.example.callfinder.MainMenu.onCreate(MainMenu.java:27)
05-28 00:55:08.634: E/AndroidRuntime(28026): at android.app.Activity.performCreate(Activity.java:5104)
05-28 00:55:08.634: E/AndroidRuntime(28026): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-28 00:55:08.634: E/AndroidRuntime(28026): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2260)
05-28 00:55:08.634: E/AndroidRuntime(28026): ... 11 more
我在做什麼錯?
LogCat:你忘了調用public void setup(LocalActivityManager activityGroup)? –
你會在該方法中加入什麼代碼?另外,Eclipse說它已經被棄用了。是否有另一個更新的選項? – Dzinic
我沒有實現它自己看看這個:http://stackoverflow.com/questions/11332482/fragmentmanager-localactivitymanager-and-tabhost-setup –