データベースの値に応じて ListView にアイコンを表示したいと思います。私はそうするためにこの答えに従います。しかし、結果として何も表示されません。これが私のrow.xmlにあるものです:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<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"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@+id/movie_name"
...
コードは次のとおりです。
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 > 0) { // subscribed movie item
ImageView movieIcon = (ImageView) view;
movieIcon.setImageResource(R.drawable.star_off);
}
break;
}
return false;
}
} );
特に、私のコードではデフォルトのアイコンと同じアイコンを使用しています。ここで何が問題なのですか?(私はstar_off
とdrawable-hdpi
フォルダーdrawable-mdpi
のみを持っています)
更新。次のコードはうまく機能します。
movieIcon.setImageDrawable(getResources().getDrawable(R.drawable.star_off));