Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy setImageResource displays nothing?
    primarykey
    data
    text
    <p>I would like to display an icon in my ListView depending on the database value. I follow <a href="https://stackoverflow.com/questions/2192082/android-changing-an-imageview-src-depending-on-database-field-data/2193727#2193727">this</a> answer to do so. But in result nothing is displayed. Here is what I have in my <strong>row.xml</strong>:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"&gt; &lt;ImageView android:id="@+id/movie_subscribed_icon" android:padding="3dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/star_off"/&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"&gt; &lt;TextView android:id="@+id/movie_name" ... </code></pre> <p>and here is the code:</p> <pre><code> movies.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { int viewId = view.getId(); switch(viewId) { case R.id.movie_name: int readValue = cursor.getInt(cursor.getColumnIndexOrThrow(MoviesDbAdapter.KEY_READ)); if (readValue == 1) { // viewed movie item TextView movieName = (TextView) view; movieName.setTextColor(Color.GRAY); } break; case R.id.movie_subscribed_icon: int subscribedValue = cursor.getInt(cursor.getColumnIndexOrThrow(MoviesDbAdapter.KEY_READ)); if (subscribedValue &gt; 0) { // subscribed movie item ImageView movieIcon = (ImageView) view; movieIcon.setImageResource(R.drawable.star_off); } break; } return false; } } ); </code></pre> <p>I especially use the same icon in my code as default one. What is wrong here? (I have <code>star_off</code> in <code>drawable-hdpi</code> and <code>drawable-mdpi</code> folders only)</p> <p><strong>Upd</strong>. the following code works well:</p> <pre><code>movieIcon.setImageDrawable(getResources().getDrawable(R.drawable.star_off)); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    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