Note that there are some explanatory texts on larger screens.

plurals
  1. POsetText() in Android TextView does nothing
    primarykey
    data
    text
    <p>I have an Android xml layout file like this:</p> <pre><code>&lt;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"&gt; &lt;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" /&gt; &lt;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" /&gt; &lt;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" &gt; &lt;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" /&gt; &lt;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" /&gt; &lt;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" /&gt; &lt;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" /&gt; &lt;/LinearLayout&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Its a simple layout with two ImageViews on top and bottom of the screen and a LinearLayout in the middle. What I want is to get some data from a Bundle and write it in the LinearLayout. For this I have the following Java code:</p> <pre><code>public class NewsD extends Activity { private ProgressDialog m_ProgressDialog = null; private Runnable viewNews; private Bundle bundle; private News m_news = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_news_activity); bundle = this.getIntent().getExtras(); m_ProgressDialog = ProgressDialog.show(NewsD.this, this.getString(R.string.wait), this.getString(R.string.receiving, true)); runOnUiThread(new Runnable(){ @Override public void run() { getNews(); } }); } 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")); LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = vi.inflate(R.layout.activity_news_activity, null); try{ ImageView iv = (ImageView) v.findViewById(R.id.icon); TextView tt = (TextView) v.findViewById(R.id.toptext); TextView bt = (TextView) v.findViewById(R.id.bottomtext); if (iv != null) { try{ Bitmap bmp = Utils.getBitmapFromURL("http://www.myserver.com/IMG/" + m_news.getNewsPhoto()); if (bmp == null){ Log.i("PHOTO ERROR", "http://www.myserver.com/IMG/" + m_news.getNewsPhoto()); } iv.setImageBitmap(bmp); } catch (Exception e){ Log.e("IMAGE ERROR", e.getMessage() + " - " + e.getStackTrace()); } } if (tt != null) { tt.setText(m_news.getNewsTitle()); } if(bt != null){ bt.setText(m_news.getNewsText()); } TextView dt = (TextView) v.findViewById(R.id.data); Date nd = new Date(Long.parseLong(m_news.getNewsDate())*1000); Calendar cal = Calendar.getInstance(); cal.setTime(nd); dt.setText(cal.get(Calendar.DAY_OF_MONTH) + "/" + cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.YEAR)); } catch (Exception e){ Log.e("ERROR", e.getMessage()); } m_ProgressDialog.dismiss(); } } </code></pre> <p>The problem is that the 3 TextViews and the ImageView show the default text/image, specified in the xml. I have checked</p> <pre><code>ImageView iv = (ImageView) v.findViewById(R.id.icon); TextView tt = (TextView) v.findViewById(R.id.toptext); TextView bt = (TextView) v.findViewById(R.id.bottomtext); </code></pre> <p>statements and seem to work fine. They are not null. Also, data coming from the bundle is fine. I've made like 1 hour of research on this, and changed the code to add the runOnUiThread() statement to make sure the getNews() function is ran in the UI thread. But nothing works. Can anyone help me please?</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload