2011-02-25 35 views
1

我有一個TabActivity,其中兩個選項卡顯示兩個列表。我用tabHost.getTabWidget()。getChildCount()來動態改變標籤指標。但在啓動應用程序時,getChildCount返回1而不是2。在tabActivity中,tabHost.getTabWidget()。getChildCount()返回1

請幫助我..

我在這裏附上我的代碼..

@Override 
public void onTabChanged(String arg0) 
{ 
    if (LIST1_TAB_TAG == tabHost.getCurrentTabTag()) 
    { 
     ImageView iv = (ImageView)tabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.icon); 
     iv.setImageDrawable(res.getDrawable(R.drawable.rupees)); 
     Log.v("check", "onTabChanged :: ChildCount == " + tabHost.getTabWidget().getChildCount()); 

    } 

回答

3

嘗試使用getTabWidget().getTabCount()getTabWidget().getChildTabViewAt(0)

2

我認爲getChildCount()ViewGroup類繼承的方法和無關通過在標籤插件的選項卡視圖中的標籤控件標籤循環的數量在標籤活動的上下文中使用

for (int tabIndex = 0 ; tabIndex < getTabWidget().getTabCount() ; tabIndex ++) 
{ 
    View tab getTabWidget().getChildTabViewAt(tabIndex); 
} 

如果有TabHost正常活動使用

yourTabhostVariable.getTabWidget()