В моем Java-коде в Android Studio у меня есть простая структура вкладок со структурой ниже:
<TabHost
android:id="@android:id/tabhost"
....>
<LinearLayout
....>
<TabWidget
android:id="@android:id/tabs"
....>
<TextView
...
android:text="tab0" />
<TextView
...
android:text="tab1" />
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
...>
<TextView
android:id="@+id/textView_0"
android:text="content0"
..../>
<TextView
android:id="@+id/textView_1"
android:text="content1"
..../>
</FrameLayout>
</LinearLayout>
</TabHost>
В одной части моего кода мне нужно прочитать содержимое TextVeiw.
Хотя я могу прочитать заголовки вкладок с помощью приведенного ниже кода, но я не смог найти способ доступа к содержимому вкладки (я вижу контент на экране мобильного телефона
...
TabWidget tab_widgets = tabHost.getTabWidget();
FrameLayout tab_contents = tabHost.getTabContentView();
for (int index = 0; index < tab_widgets.getChildCount(); index++) {
//access tab's title: Works OK !!
View v_title =
tab_widgets.getChildAt(index).findViewById(android.R.id.title);
TextView tv_title = (TextView) v_title;
//access tab's content: NOT working ??
View v_content =
tab_contents.getChildAt(index).findViewById(android.R.id.title);
TextView tv_content = (TextView) v_content; // It is always NULL
}
Есть ли идеи по этому поводу? как я могу прочитать текст внутри тела вкладок?