EDIT:TextViewの親ScrollViewの背景を変更するだけで、以下の#2を解決しました。Androidタブのトラブル - プログラム的に内容を変更する
私は一日中グーグルで語っていますが、これに対する答えを見つけることはできません。これは簡単なはずです。
私のアクティビティには、Tabbedコントロール(TabHost、TabWidgetsなど)で構成されるフラグメントが含まれています。各タブには、シンプルなスクロールTextViewがあります。このアイデアは、ユーザーがスクロールできるテキストの異なるカテゴリを持ついくつかのタブを持つことです。私はタブなどを設定することができましたが、解決できないような2つの問題があります。
1)タブのTextViewの内容を(フラグメントを所有するアクティビティから)プログラムで変更する方法を理解できません。私は、私のホストのアクティビティ内でフラグメントを見つけ、フラグメントを自分のフラグメントクラスにキャストしてから、テキストを変更するはずのフラグメントクラス内の関数を呼び出して、FragmentManagerを作成しようとしました。この機能は単にこれを行います:
TextView textView = (TextView)tabHost.getTabWidget().getChildAt(tabNumber).findViewById(R.id.dashboard_fragment_4_textView);
if(textView!=null) textView.setText(text);
これは機能しません。 textViewは常にnullを返します。
2)レイアウトの問題、私は信じています。各タブのMy TextViewは親を満たしません。テキストコンテンツだけをラップします。これは大きな問題ではありませんが、TextViewで使用できる画面領域全体を特定の背景色にする必要があります。たぶん、これを処理するより良い方法はありますか? TextViewの背景を透明にして、TextViewの背後に何かを正しい色で表示したいのですか?私は知らない....私は到達している。ここで
は、各タブのXMLレイアウトです:任意の提案のための
<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>
感謝!!
ブライアン明らか
おかげでジェフにする必要があります。あなたのコメントはそこに私の一部を得た。私はまた、私のXMLレイアウトを変更する必要がありました。私はまた各タブページのための別のScrollView/TextViewを持っている私のXMLファイルを変更しなければなりません...それは私がそれについて考えて今意味があります。これを処理するよりエレガントな方法があるかもしれませんが、それは私のために働いた。再度、感謝します! –