Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android从上下文获取tabhost并禁用它_Android_Android Tabhost - Fatal编程技术网

Android从上下文获取tabhost并禁用它

Android从上下文获取tabhost并禁用它,android,android-tabhost,Android,Android Tabhost,我正在尝试从上下文获取TabHost。下面是代码,但它不起作用 public final static void disableTabs(Context context) { TabHost tabHost = (TabHost) ((Activity) context).getParent() .findViewById(android.R.id.tabhost); tabHost.getTabWidget().getChildT

我正在尝试从上下文获取TabHost。下面是代码,但它不起作用

public final static void disableTabs(Context context) {
        TabHost tabHost = (TabHost) ((Activity) context).getParent()
                .findViewById(android.R.id.tabhost);
        tabHost.getTabWidget().getChildTabViewAt(1).setEnabled(false);
        tabHost.getTabWidget().getChildTabViewAt(2).setEnabled(false);
        tabHost.getTabWidget().getChildTabViewAt(3).setEnabled(false);
    }
我是这样称呼它的

Constants.disableTabs(HomeController.this);
我找到了解决办法

替换

TabHost tabHost = (TabHost) ((Activity) context).getParent()
                .findViewById(android.R.id.tabhost)


因为我的Tabhost在ActivityGroup中,android.R.id.Tabhost在我们将TabActivity作为父类时起作用,所以只需将其更改为R.id.Tabhost

NullPointerException,即Tabhost变量为null。您确定选项卡在
Activity
中,而不是
ActivityGroup
中吗?因为我认为活动本身无法显示选项卡。rite?TabHost存在于activitygroup中,并且activities正在添加到activitygroup中的TabHost中。HomeController是activitygroup内部的
Activity
,还是它本身是
activitygroup
呢?我想如果您粘贴一些更合理的代码,那么,如果你能弄明白这一点,我们就可以帮助moregood了。我相信你的家庭控制器是一个活动团体。如果是这样的话,那么相反,如果您将
活动
更改为
活动组
,它仍然可以正常工作,并且更有意义
TabHost tabHost = (TabHost) ((Activity) context).getParent()
                .findViewById(R.id.tabhost)