2011-02-25 43 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()