2012-12-19 38 views
1

我正在使用一個標籤主機兩個顯示兩個列表上的兩個標籤,但我希望當點擊第二個標籤時,它應該重新加載第一個標籤data.How是可能的嗎? 我的代碼是這樣的安卓標籤主機不刷新數據

TabHost tabs = (TabHost)findViewById(R.id.tabhost_spices); 
    tabs.setup();`enter code here` 
TabHost.TabSpec tab1 = tabs.newTabSpec("tab1"); 

    tab1.setContent(R.id.list_spices_fav); 
    tab1.setIndicator("Favorite",getContext().getResources().getDrawable(R.drawable.tab_fav_icon)); 

    tabs.addTab(tab1); 

    // create tab 2 
    TabHost.TabSpec tab2 = tabs.newTabSpec("tab2"); 
    tab2.setContent(R.id.list_spices_categories); 

    tab2.setIndicator("View List",getContext().getResources().getDrawable(R.drawable.tab_cat_icon)); 
    tabs.addTab(tab2); 

回答

2

這裏是一個教程,這幫助我 - link

0

對於令人耳目一新的新選項卡中的數據,你必須保持代碼爲refereshing內部的活動onResume()的數據,因爲當創建TabActivity其所有選項卡撥打電話到相應的活動調用它的onResume()onCreate()'. So, when you click the Tab once its loaded its()method is called and not onCreate()`。

+0

如何在課堂上使用的onResume是擴展對話框類?拜託,我不會用我用tabhost對話框類中tabactivity告訴 –

1

使用TabActivity擴展您的活動

TabHost tabHost;

tabHost = getTabHost(); 
Resources res = getResources(); 
TabSpec tabspec1 = tabHost.newTabSpec("").setIndicator("Tab1",res.getDrawable(R.drawable.ic_launcher)).setContent(new Intent(this, FirstActivity.class)); 
    tabHost.addTab(tabspec1); 

TabSpec tabspec2 = tabHost.newTabSpec("").setIndicator("Tab2",res.getDrawable(R.drawable.ic_launcher)).setContent(new Intent(this, SecondActivity.class)); 
    tabHost.addTab(tabspec2); 
+0

? –