0
我只是试图更改我的选项卡名称,因为我在我的选项卡中包含了布局,并且我无法更改XML中的名称或至少找不到方法。Android:更改选项卡名称 - nullPointerException
这是布局(部分):
<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"); //<--------------------
}
在我的代码必须在标线一个NullPointerException。我可以轻松获得tabwidget,但只要我尝试getChildAt,我有例外,但我不明白为什么。
你能帮我吗?
尝试'setIndicator(“Data”)'而不是'setText(“New”)' –
放置断点并检查你得到的“th”。 –
我得到了GetChildAt的错误,这是因为tabwidget没有孩子,但它不可能吗?我添加了3个布局,SDK向我显示了3个选项卡!这是怎么发生的? – rXp