Android изменить текстовое представление вне TabWidget в деятельности - PullRequest
2 голосов
/ 15 ноября 2011

У меня есть приложение с несколькими вкладками, которые принадлежат одному и тому же TabHost. Есть ли способ изменить значение TextView android:text перед TabWidget в любом действии, кроме основного, которое распространяется на TabActivity?

Это мой main.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/sigma_darkgray">
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/title_color"
            android:text="Home page"
            android:textStyle="bold"
            android:paddingTop="6dip"
            android:paddingBottom="6dip"
            android:gravity="center_horizontal"
            android:textAppearance="?android:attr/textAppearance"/>
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingTop="1dip"
            android:background="@color/title_color"/>
        <View android:id="@+id/separator" 
            android:background="#ffffff"
            android:layout_width = "fill_parent"
            android:layout_height="1dip"
            android:layout_centerVertical ="true"
            android:layout_alignParentTop="true"/>     
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>
</TabHost>

Ответы [ 2 ]

2 голосов
/ 15 ноября 2011

В активности, начатой ​​с TabHost

((MyParentActivity)getParent()).setYourText("whatever")

где вы должны создать метод "setYourText (String text)".

2 голосов
/ 15 ноября 2011

Да, Вы можете.Просто дайте идентификатор TextView.И объявите ссылку на это текстовое представление в MainActivity, где там, т. Е. TabActivity, расширено.

Теперь в другом дочернем действии Вы можете вызвать этот textView с объектом MainActivity.textview.

Теперь вы можете изменитьTextValue textView, и это делается из дочерней деятельности.

Наслаждайтесь.

...