隐藏在TabHost在Android的一个标签 [英] Hide a tab in the TabHost in Android

查看:194
本文介绍了隐藏在TabHost在Android的一个标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 如果(......)
    {
        tabHost.getTabWidget()getChildAt(0).setVisibility(View.GONE)。
                    //隐藏在TabHost第一个选项卡    }

这有什么不对的code?应用程序崩溃时,我添加此code中的onCreate()方法里面..
任何想法?

我的LogCat中:

  05-31 22:03:38.471:E / AndroidRuntime(598):05-31显示java.lang.NullPointerException 22:03:38.471:致E / AndroidRuntime(598 ):在swayam.dev.mushtouch.MushTouchActivity.setVisibilityControls(MushTouchActivity.j AVA:75)05-31 22:03:38.471:E / AndroidRuntime(598):在swayam.dev.mushtouch.MushTouchActivity.onCreate(MushTouchActivity。 Java的:220)05-31 22:03:38.471:E / AndroidRuntime(598):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)05-31 22:03:38.471:E / AndroidRuntime(598) :在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

也试过这code。仍保持崩溃。

  getTabHost()getTabWidget()removeViewAt(0);


解决方案

我的回答将是太长如此虐待把它放在一个答案。

到目前为止,您有

  TabHost tabHost =(TabHost)findViewById(android.R.id.tabhost);
tabHost.getTabWidget()getChildAt(0).setVisibility(View.GONE)。

您得到一个NullPointerException异常,也就是说,只要你使用的是该行code的,你想改变一些东西,这并不在屏幕上,或可能的东西关闭屏幕存在。

检查import语句R.

下面的包语句,你应该具备以下条件:

 进口your.package.R;

而不是

 进口android.R;

一旦是固定的,当你引用你的标签的主机,使用以下命令:

  TabHost tabHost =(TabHost)findViewById(R.id.tabhost);

如果那不工作,确保tabhost实际上是在屏幕上,你不能在一个单独的活动。

if( ......)
    {


        tabHost.getTabWidget().getChildAt(0).setVisibility(View.GONE);
                    //to hide the first tab in the TabHost

    }

Is there anything wrong with this code ? The application crashes when I add this code inside the onCreate() method.. Any idea ?

My LogCat :

05-31 22:03:38.471: E/AndroidRuntime(598): Caused by: java.lang.NullPointerException 05-31 22:03:38.471: E/AndroidRuntime(598): at swayam.dev.mushtouch.MushTouchActivity.setVisibilityControls(MushTouchActivity.j‌​ava:75) 05-31 22:03:38.471: E/AndroidRuntime(598): at swayam.dev.mushtouch.MushTouchActivity.onCreate(MushTouchActivity.java:220) 05-31 22:03:38.471: E/AndroidRuntime(598): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 05-31 22:03:38.471: E/AndroidRuntime(598): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

Also tried this code. Still keeps crashing.

getTabHost().getTabWidget().removeViewAt(0);

解决方案

My response is going to be too long so ill put it in an answer.

So far you have

TabHost  tabHost = (TabHost)findViewById(android.R.id.tabhost);
tabHost.getTabWidget().getChildAt(0).setVisibility(View.GONE);

You are getting a NullPointerException, meaning that whenever you are using that line of code, you are trying to change something that doesn't exist on screen, or possibly something off screen.

Check your Import statement for R.

Below your package statement you should have the following:

import your.package.R;

and not

import android.R;

Once that is fixed, when you reference your tab host, use the following:

TabHost  tabHost = (TabHost)findViewById(R.id.tabhost);

If that doesnt work, make sure the tabhost is actually on the screen and that your not in a seperate activity.

这篇关于隐藏在TabHost在Android的一个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆