【发布时间】:2012-03-04 00:05:38
【问题描述】:
我有一个自定义光标适配器,我想将图像放入 ListView 中的 ImageView 中。
我的代码是:
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);
}
}
这没关系,但我想从数据库(光标)中获取图像的名称。 我试过了
String mDrawableName = "myImageName";
int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName());
但返回错误:“CustomImageListAdapter 类型的方法 getResources() 未定义”
【问题讨论】:
-
如果您想从 Cursor 获取信息,为什么不致电
cursor.getString。您的图像存储在哪里?
标签: android android-listview android-imageview