1

我有一个 TabActivity 有两个选项卡显示两个列表。我使用 tabHost.getTabWidget().getChildCount() 动态更改选项卡指示器。但是在启动应用程序时 getChildCount 返回 1 而不是 2。

请帮我..

我在这里附上我的代码..

 @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() );

    }
4

2 回答 2

3

尝试使用getTabWidget().getTabCount()getTabWidget().getChildTabViewAt(0)

于 2011-02-26T00:03:49.613 回答
2

我认为getChildCount()是从ViewGroup类继承的方法,与选项卡小部件中的选项卡数量无关,以循环使用选项卡小部件中的选项卡视图

在选项卡活动的上下文中

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

如果使用 TabHost 进行正常活动

yourTabhostVariable.getTabWidget()
于 2012-07-23T10:26:49.060 回答