Mam niestandardowy adapter kursora i chciałbym umieścić obraz w ImageView w widoku listy.Pobierz obraz zasobu według nazwy w niestandardowy adapter kursora.
Mój kod to:
public class CustomImageListAdapter extends CursorAdapter {
private LayoutInflater inflater;
public CustomImageListAdapter(Context context, Cursor cursor) {
super(context, cursor);
inflater = LayoutInflater.from(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// get the ImageView Resource
ImageView fieldImage = (ImageView) view.findViewById(R.id.fieldImage);
// set the image for the ImageView
flagImage.setImageResource(R.drawable.imageName);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return inflater.inflate(R.layout.row_images, parent, false);
}
}
To wszystko jest OK, ale chciałbym uzyskać nazwę obrazu z bazy danych (kursora). Próbowałem z
String mDrawableName = "myImageName";
int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName());
Ale błąd powrotu: "The getResources() metoda jest niezdefiniowana dla CustomImageListAdapter typu"
Jeśli chcesz uzyskać od Cursora, dlaczego nie nazywasz 'cursor.getString' zamiast tego. A gdzie jest przechowywany twój obraz? –