私は次のコードを取得java.lang.NullPointerException
しています。createTabContent
2つのタブスペックがあります。呼び出してタブを設定したときに、初めてタブを変更しても問題ありません。しかし、2番目のタブを表示しているときにもう一度呼び出すと、次の行のnullポインター例外が発生します。NoStudentText.setVisibility(View.VISIBLE);
学生リストのデータがない場合は、学生テキストなしを表示します。初めての通話のテキストが表示されます。しかし、そのタブを2回呼び出すと、エラーが発生します。
tspecStudent.setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
if(listStudent != null && listStudent .size() > 0) {
//show the student list
} else {
TextView noStudentText = (TextView)findViewById(R.id.NoStudentText);
noStudentText.setVisibility(View.VISIBLE);
return noStudentText;
}
}
});
メインレイアウトに別のxmlを含めています。
main.xml
<TabHost
android:id="@+id/tabhostMain"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
....
<include layout="@layout/tab_student" />
</TabHost>
tab_student.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:id="@+id/StudentList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false" />
<TextView
android:id="@+id/NoStudentText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No Student"
android:visibility="gone" />
</FrameLayout>