Android TextView中的setText()不起任何作用

Android TextView中的setText()不起任何作用,android,android-layout,Android,Android Layout,我有一个Android xml布局文件,如下所示: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#184A

我有一个Android xml布局文件,如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:background="#184A64">

<ImageView
    android:id="@+id/logoTop"
    android:layout_width="fill_parent"
    android:layout_height="42dip"
    android:layout_alignParentTop="true"
    android:layout_gravity="center"
    android:background="#F1CF2F"
    android:contentDescription="@string/descLogoTop"
    android:padding="4dip"
    android:src="@drawable/logoTop" />

<ImageView
    android:id="@+id/logoBot"
    android:layout_width="fill_parent"
    android:layout_height="42dip"
    android:layout_alignParentBottom="true"
    android:layout_gravity="center"
    android:background="#F1CF2F"
    android:contentDescription="@string/descLogoBot"
    android:padding="4dip"
    android:src="@drawable/logoBot" />

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/logoTop"
    android:orientation="vertical"
    android:padding="6dip" >

    <TextView
        android:id="@+id/data"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:text="date"
        android:textColor="#FFFFFF"
        android:textSize="12sp"
        android:textStyle="normal" />

    <ImageView
        android:id="@+id/icon"
        android:layout_width="103dip"
        android:layout_height="62dip"
        android:layout_marginBottom="6dip"
        android:layout_marginRight="6dip"
        android:contentDescription="@string/descLogo"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/toptext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:text="title"
        android:textColor="#F1CF2F"
        android:textSize="12sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/bottomtext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:singleLine="false"
        android:text="text"
        android:textColor="#FFFFFF"
        android:textSize="12sp" />
</LinearLayout>
</RelativeLayout>
public void getNews() {

    m_news = new News();
    m_news.setNewsTitle(bundle.getString("title"));
    m_news.setNewsText(bundle.getString("text"));
    m_news.setNewsDate(bundle.getString("data"));
    m_news.setNewsPhoto(bundle.getString("photo"));



    try{
        ImageView iv = (ImageView) findViewById(R.id.icon);
        TextView tt = (TextView) findViewById(R.id.toptext);
        TextView bt = (TextView) findViewById(R.id.bottomtext);
问题在于,3个TextView和ImageView显示xml中指定的默认文本/图像。我查过了

ImageView iv = (ImageView) v.findViewById(R.id.icon);
TextView tt = (TextView) v.findViewById(R.id.toptext);
TextView bt = (TextView) v.findViewById(R.id.bottomtext);
语句和语句似乎工作正常。它们不是空的。此外,来自捆绑包的数据也可以。我对此做了大约1个小时的研究,并更改了代码以添加runOnUiThread()语句,以确保getNews()函数在UI线程中运行。但什么都不管用。有人能帮我吗


提前感谢。

好的,问题是您正在将getNews调用中的视图膨胀到内存中,但该视图不会显示。调用setContentView后,视图将已膨胀。因此,请使用如下视图:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:background="#184A64">

<ImageView
    android:id="@+id/logoTop"
    android:layout_width="fill_parent"
    android:layout_height="42dip"
    android:layout_alignParentTop="true"
    android:layout_gravity="center"
    android:background="#F1CF2F"
    android:contentDescription="@string/descLogoTop"
    android:padding="4dip"
    android:src="@drawable/logoTop" />

<ImageView
    android:id="@+id/logoBot"
    android:layout_width="fill_parent"
    android:layout_height="42dip"
    android:layout_alignParentBottom="true"
    android:layout_gravity="center"
    android:background="#F1CF2F"
    android:contentDescription="@string/descLogoBot"
    android:padding="4dip"
    android:src="@drawable/logoBot" />

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/logoTop"
    android:orientation="vertical"
    android:padding="6dip" >

    <TextView
        android:id="@+id/data"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:text="date"
        android:textColor="#FFFFFF"
        android:textSize="12sp"
        android:textStyle="normal" />

    <ImageView
        android:id="@+id/icon"
        android:layout_width="103dip"
        android:layout_height="62dip"
        android:layout_marginBottom="6dip"
        android:layout_marginRight="6dip"
        android:contentDescription="@string/descLogo"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/toptext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:text="title"
        android:textColor="#F1CF2F"
        android:textSize="12sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/bottomtext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:singleLine="false"
        android:text="text"
        android:textColor="#FFFFFF"
        android:textSize="12sp" />
</LinearLayout>
</RelativeLayout>
public void getNews() {

    m_news = new News();
    m_news.setNewsTitle(bundle.getString("title"));
    m_news.setNewsText(bundle.getString("text"));
    m_news.setNewsDate(bundle.getString("data"));
    m_news.setNewsPhoto(bundle.getString("photo"));



    try{
        ImageView iv = (ImageView) findViewById(R.id.icon);
        TextView tt = (TextView) findViewById(R.id.toptext);
        TextView bt = (TextView) findViewById(R.id.bottomtext);

我相信,您正在获得NetworkOnMainThreadException,但由于您正在捕获异常,您正在丢失有关您正在获得的异常的数据。RunOnuiThread在您的情况下不是正确的方式

使用Asynctask并将所有UI代码(例如layoutinflation、setText、setImageBitmap)移动到OnPreExecute或OnPostExecute,并移动到Asynctask的doInbackground行下方

Bitmap bmp = Utils.getBitmapFromURL("http://www.myserver.com/IMG/" + m_news.getNewsPhoto());

虽然如果在果冻豆上运行,他也会得到那个错误。