EDIT: I solved #2 below by simply changing the background of the TextView’s parent ScrollView.
I’ve been googling all day, but just can’t seem to find the answer to this. This should be simple.
My activity contains a fragment that is made up of a Tabbed control (TabHost, TabWidgets, etc.). On each tab is a simple, scrolling TextView. The idea is to have a few tabs with different categories of text that the user can scroll through. I’ve been able to set up the tabs and such, but have 2 problems that I can’t seem to solve.
1) I can’t figure out how to change the contents of a tab’s TextView programmatically (from the Activity that owns the fragment). I’ve tried creating a FragmentManager inside my host activity, finding the fragment, casting the fragment to my fragment class, then calling a function inside the fragment class that is supposed to change the text. This function simply does this:
TextView textView = (TextView)tabHost.getTabWidget().getChildAt(tabNumber).findViewById(R.id.dashboard_fragment_4_textView);
if(textView!=null) textView.setText(text);
This doesn’t work; textView always returns as null.
2) A layout issue, I believe. My TextView on each tab doesn’t fill the parent; it just wraps the text content. This is not a huge deal, but I want the entire screen area available to the TextView to have a particular background color. Maybe there’s a better way to handle this??? Like having the TextView’s background transparent, and then having something behind the TextView with the right color? I don’t know….I’m reaching.
Here’s the xml layout for each tab:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:gravity="left"
android:layout_weight="0" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1">
<ScrollView
android:id="@+id/dashboard_fragment_4_scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/dashboard_fragment_4_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/Linen"
android:textColor="@color/Black"
android:textSize="20dp"
android:text="TextView" />
</ScrollView>
</FrameLayout>
</LinearLayout>
Thanks for any suggestions!!
Bryan
Obviously, it should be tabs.getTabContentView() instead of tabHost.getTabWidget()