我在一個基於標籤視圖無法獲得工作片段選項卡控制器
ToDoActivity.class Android項目以下設置:
private FragmentTabHost mTabHost;
private User user;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_todos);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String username = bundle.getString("username");
this.user = new User(TodoActivity.this, username);
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
// Tab for 'active' tasks
TabSpec tasksTab = mTabHost.newTabSpec("Tasks");
// setting Title and Icon for the Tab
tasksTab.setIndicator("Tasks", getResources().getDrawable(R.drawable.icon_tasks_tab));
Intent activeIntent = new Intent(this, ActiveTasks.class);
tasksTab.setContent(activeIntent);
// Tab for completed tasks
TabSpec compeltedTasks = mTabHost.newTabSpec("Completed");
compeltedTasks.setIndicator("Completed", getResources().getDrawable(R.drawable.icon_completed_tab));
Intent completedIntent = new Intent(this, CompletedTasks.class);
compeltedTasks.setContent(completedIntent);
// Adding all TabSpec to TabHost
mTabHost.addTab(tasksTab);
mTabHost.addTab(compeltedTasks);
}
activity_todos:XML
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
每當我運行它並嘗試過渡到選項卡視圖時,出現以下錯誤:
02-24 10:03:38.705: E/AndroidRuntime(3791): java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.gatech.team6.todo/edu.gatech.team6.todo.TodoActivity}: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
但我確實打電話給安裝程序?
我已閱讀文檔,活動(ActiveTasks和CompletedTasks)都是Fragment對象。這不是FragmentTabHost打算工作的方式嗎? – patrick