0

我目前卡在一个点。如果我使用带有片段的操作栏(NAVIGATION_MODE_TABS)。我希望片段成为一个活动,它将处理所有视图加载和所有内容。当前片段类将扩展片段..对吗?但我想要像扩展活动然后调用 oncreate 之类的东西。

请帮忙。

enter code here

final TabHost tabHost = getTabHost();//(TabHost) findViewById(R.id.tabhost);//  // The activity TabHost
    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab
    // Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, X.class);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("jbn jb n").setIndicator("gjngjmb ",
                      res.getDrawable(R.drawable.home))
                  .setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs
    intent = new Intent().setClass(this, MyCoursesActivity.class);
    spec = tabHost.newTabSpec("my_course").setIndicator("My Courses",
                      res.getDrawable(R.drawable.courses))
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, DashboardActivity.class);
    intent.putExtra("course_title", "Aal is well!!!");
    spec = tabHost.newTabSpec("dashboard").setIndicator("Dashboard",
                      res.getDrawable(R.drawable.dashboard))
                  .setContent(intent);
    tabHost.addTab(spec);

enter code here

此代码正在使用 tabhost 我想使用带有 android 4.0 片段的操作栏来做同样的事情

4

1 回答 1

0

您可以onCreateView()在 Fragment 上使用,也getActivity().可以让您直接访问Activity

于 2012-12-06T08:34:51.627 回答