2012-12-06 18 views
0

我目前卡在一個point.If我使用操作欄(NAVIGATION_MODE_TABS)與片段。我想片段是一個活動,它將處理所有的視圖加載和一切。當前fragmented類將擴展Fragment..Right?但我想somethth喜歡擴展活動,然後調用oncreate。動作Android的動作酒吧與片段加載視圖,但我想加載自己加載視圖的活動(如在tabhost)

請幫忙。

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我想要做同樣的使用動作條與fragmants爲Android 4.0

回答

0

您可以使用片段onCreateView(),也getActivity().會給你直接訪問Activity