我正在從一個從互聯網上獲取信息的應用程序工作。信息按類別,子類別和子子類別分類。更改標籤主機意圖
我的主視圖是一個包含3個選項卡和初始列表視圖(子類別)的TabHost視圖(父類別)。當用戶點擊列表視圖中的項目時,它會調用一個新的列表視圖,顯示所選子類別的子類別。
我得到了一切工作,除了當選擇一個子類別時,tabHost視圖消失並且子子類別全屏顯示。
如何更改選項卡的意圖以顯示子類別的子類別?
編輯:這是我的代碼,對不起,我沒有發佈它!其中包含tabhost
我的主要觀點:
public class tabwidget extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
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, category1Activity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("category1").setIndicator("Category1",
res.getDrawable(R.drawable.ic_tab_category1))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, category2Activity.class);
spec = tabHost.newTabSpec("category2").setIndicator("Category2",
res.getDrawable(R.drawable.ic_tab_category2))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, category3Activity.class);
spec = tabHost.newTabSpec("category3").setIndicator("Category3",
res.getDrawable(R.drawable.ic_tab_category3))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
當應用程序被啓動的酒標籤被默認選中。這是category1Acitivity列表視圖與調用子類別的onlclick行動:
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//Toast.makeText(getApplicationContext(), "You clicked item at position"+position,
//Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Loading "+((TextView) view.findViewById(R.id.categoryname)).getText(),
Toast.LENGTH_SHORT).show();
Intent i = new Intent(category1Activity.this, subCategoryActivity.class);
i.putExtra("id", ((TextView) view.findViewById(R.id.message)).getText());
i.putExtra("catname", ((TextView) view.findViewById(R.id.categoryname)).getText());
i.putExtra("parentcatid", "0");
startActivityForResult(i, ACTIVITY_CREATE);
}
});
的列表視圖,通過它發送到服務器的類ID生成是直接從數據庫結果。
太感謝你了!這是完美的,經過一些微調我設法讓它工作:) – 2011-12-27 20:30:03
不客氣:) – Dante 2011-12-27 21:14:38