English 中文(简体)
图卢布与安伯斯-方案变化的内容
原标题:Trouble with Android Tabs -- programmatically changing contents

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.

我的活动包含由塔皮斯控制(TabHost、TabWidgets等)组成的碎片。 每一表格都是简单、滚动案文。 想法是,有几条表格,用户可以浏览不同类型的文本。 我早就能够提出这些表格,但我似乎无法解决两个问题。

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);

本文案文 观点永远无效。

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.

每一表的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>

感谢任何建议!

布赖恩

最佳回答

很显然,这应该成为表象。

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签