Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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:更改选项卡名称-nullPointerException_Android_Tabs - Fatal编程技术网

Android:更改选项卡名称-nullPointerException

Android:更改选项卡名称-nullPointerException,android,tabs,Android,Tabs,我只是尝试更改选项卡名称,因为我在选项卡中包含了布局,但在XML中无法更改名称,或者至少我找不到如何更改 <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="360dp" android:layout_above="@+id/button_gamecfg_save" > <include android:layou

我只是尝试更改选项卡名称,因为我在选项卡中包含了布局,但在XML中无法更改名称,或者至少我找不到如何更改

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="360dp"
android:layout_above="@+id/button_gamecfg_save" >

<include
android:layout_width="wrap_content"
android:layout_height="match_parent"
layout="@layout/gamecfg_times" />

<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/gamecfg_others" />

<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/gamecfg_roles" />

</FrameLayout>
这是布局图(部分):

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="360dp"
android:layout_above="@+id/button_gamecfg_save" >

<include
android:layout_width="wrap_content"
android:layout_height="match_parent"
layout="@layout/gamecfg_times" />

<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/gamecfg_others" />

<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/gamecfg_roles" />

</FrameLayout>

我的代码是:

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="360dp"
android:layout_above="@+id/button_gamecfg_save" >

<include
android:layout_width="wrap_content"
android:layout_height="match_parent"
layout="@layout/gamecfg_times" />

<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/gamecfg_others" />

<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/gamecfg_roles" />

</FrameLayout>
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gamecfg_tabs);
    TabHost th=((TabHost)findViewById(android.R.id.tabhost));
    ((TextView)th.getTabWidget().getChildAt(0).findViewById(android.R.id.title)).setText("New"); //<--------------------
}
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.gamecfg_选项卡);
TabHost th=((TabHost)findviewbyd(android.R.id.TabHost));

((TextView)th.getTabWidget().getChildAt(0).findViewById(android.R.id.title)).setText(“新建”);//是否尝试在getChildAt(0)之前调用方法th.setup()

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="360dp"
android:layout_above="@+id/button_gamecfg_save" >

<include
android:layout_width="wrap_content"
android:layout_height="match_parent"
layout="@layout/gamecfg_times" />

<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/gamecfg_others" />

<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/gamecfg_roles" />

</FrameLayout>
文件说:
“如果使用findViewById()加载TabHost,请在添加选项卡之前调用setup()。”

尝试
setIndicator(“数据”)
而不是
setText(“新建”)
放置断点并检查“th”的结果”.我在GetChildAt上得到错误,这是因为tabwidget没有子项,但它不可能是吗?我添加了3个布局,SDK显示了3个选项卡!这是怎么发生的?
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="360dp"
android:layout_above="@+id/button_gamecfg_save" >

<include
android:layout_width="wrap_content"
android:layout_height="match_parent"
layout="@layout/gamecfg_times" />

<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/gamecfg_others" />

<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/gamecfg_roles" />

</FrameLayout>