2011-10-23 12 views
0
public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 

      TabHost tabHost = (TabHost) findViewById(R.id.tabhostscreen_tabhost); 
      mLocalActivityManager = new LocalActivityManager(this, false); 

      tabHost.setup(mLocalActivityManager); 
      mLocalActivityManager.dispatchCreate(savedInstanceState); //after the tab's setup is called, you have to call this or it wont work 

      TabHost.TabSpec spec; 
      Intent intent; 
      //set up your tabs here. It's easy to just do seperate activities for each tab, and link them in here. 
      intent = new Intent().setClass(this, SomeActivity.class); 
      spec = tabHost.newTabSpec("tagname1").setIndicator("tab indicator 1", getResources().getDrawable(R.drawable.icon)).setContent(intent); 
      tabHost.addTab(spec); 

      intent = new Intent().setClass(this, SomeOtherActivity.class); 
      spec = tabHost.newTabSpec("tagname2").setIndicator("tab indicator 2").setContent(intent); 
      tabHost.addTab(spec); 
    } 

これらのタブにエキストラを追加することはできますか?タブにエキストラを追加する

答えて

0

はい、追加することができます。

intent = new Intent().setClass(this, SomeActivity.class); 
    intent.putExtra("this_is_my_extra", "hello world!"); 

    spec = tabHost.newTabSpec("tagname1").setIndicator(...); 
    spec.setContent(intent); 
    tabHost.addTab(spec); 
+0

これはうまくいきました。私はちょうどこのようにするのは不可能だと言って、多くの記事を読んでいますが、この作品です。 – Tsunaze

関連する問題