我有一個TabActivity託管許多選項卡。每個選項卡都指向相同的活動,但是邏輯在確定要加載的內容的活動中執行。我希望通過將布爾值傳遞給相應的選項卡來完成此操作。我怎樣才能做到這一點?如何將附加內容傳遞給TabActivity中的意圖?
package com.stocktwits.activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class StockTwitsTabActivity extends TabActivity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.stocktwits_tab_activity);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // 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, StreamActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
intent.putExtra("reloadAll", true);
spec = tabHost.newTabSpec("all").setIndicator("All",res.getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, StreamActivity.class);
spec = tabHost.newTabSpec("home").setIndicator("Home",res.getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, StreamActivity.class);
spec = tabHost.newTabSpec("mentions").setIndicator("Mentions",res.getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, StreamActivity.class);
spec = tabHost.newTabSpec("directs").setIndicator("Directs",res.getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, StreamActivity.class);
spec = tabHost.newTabSpec("more").setIndicator("More",res.getDrawable(R.drawable.icon)).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
你爲什麼要使用活動,而不是一個視圖如果視圖是始終爲每個標籤相同的目的,有效的解決方案嗎?我想你可以使用'android.widget.TabHost.OnTabChangeListener'並在這裏處理主視圖 – 2010-11-19 23:57:30
的內容你能否提供一個TabHost的例子來加載視圖而不是活動? – 2010-11-20 02:02:51