我想成立一個tabHost和列表中的一個在另一個之下,所以我把它添加到一個垂直線性佈局,但是當我嘗試addView標籤主機通過活動安排上面列表中的tabHost
public TabHost peopleTabHost;
private void CreateNewTab(String tagName, String displayedName, Class<?> intentClass)
{
Intent intent = new Intent().setClass(this, intentClass);
TabHost.TabSpec spec = peopleTabHost.newTabSpec(tagName).setIndicator(displayedName);
spec.setContent(intent);
peopleTabHost.addTab(spec);
}
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
LayoutParams rootParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
LinearLayout rootLayout = new LinearLayout(this);
rootLayout.setLayoutParams(rootParams);
rootLayout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams listParams = new LinearLayout.LayoutParams(0, LayoutParams.FILL_PARENT);
listParams.weight = 1;
ListView lv_chosen = new ListView(this);
lv_chosen.setLayoutParams(listParams);
lv_chosen.setTextFilterEnabled(true);
peopleTabHost = getTabHost();
CreateNewTab("groups", "Groups", GroupsActivity.class);
CreateNewTab("everyone", "Everyone", EveryoneActivity.class);
CreateNewTab("contacts", "Contacts", ContactsActivity.class);
peopleTabHost.setCurrentTabByTag("everyone");
rootLayout.addView(peopleTabHost);
rootLayout.addView(lv_chosen);
}
崩潰
感謝
謝謝,但一開始喜歡你並顯示墜毀時,我試圖以一個新的標籤添加到它,當我把它就像我的代碼顯示它並沒有崩潰了我所做的peopleTabHost。我確實定義了它,如果你的意思是在創建新的選項卡方法之上。另外,方法setTabHost(TabHost)未定義。 – Someonation 2012-01-02 16:11:20