Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid View does not show
    primarykey
    data
    text
    <p>I have this Android Activity layout 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:padding="6dip" &gt; &lt;TextView android:id="@+id/data" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="left" android:text="" 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="" 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="" android:textColor="#FFFFFF" android:textSize="12sp" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>This xml defines a layout with a top rectangle with a log in it, and also a bottom rectangle with a logo in it. Those two elements are displayed correctly. But the middle component is a Linear Layout with a TextView, then an Image, and then 2 TextViews. This component doesn't show. The Java code for the activity goes like this:</p> <pre><code>public class NewsActivity 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(); viewNews = new Runnable(){ @Override public void run() { getNews(); } }; Thread thread = new Thread(null, viewNews, "MagentoBackground"); thread.start(); m_ProgressDialog = ProgressDialog.show(NewsActivity.this, this.getString(R.string.wait), this.getString(R.string.receiving, true)); } public void getNews() { m_news = new News(); m_news.setNewsTitle(bundle.getString("title")); m_news.setNewsText(bundle.getString("text")); m_news.setNewsDate(bundle.getString("date")); 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 NEWS", e.getMessage()); } runOnUiThread(returnRes); } private Runnable returnRes = new Runnable() { @Override public void run() { m_ProgressDialog.dismiss(); } }; } </code></pre> <p>What I am doing here is to extract some data from the bundle (it works properly), and then set contents to the TextViews and the ImageView. But, when I test this on the emulator the Image and TextViews are empty. </p> <p>I've checked the calls</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>and, aparently, then dont return null. But if a do </p> <pre><code>tt.setText("some random text here"); </code></pre> <p>it doesn't work.</p> <p>I think I'm not doing something right. Can anyone help me please?</p>
    singulars
    1. This table or related slice is empty.
    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