में नाम से संसाधन छवि प्राप्त करें मेरे पास एक कस्टम कर्सर एडाप्टर है और मैं एक सूची दृश्य में एक छवि दृश्य में एक छवि डालना चाहता हूं।कस्टम कर्सर एडाप्टर
मेरे कोड है:
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());
साथ करने की कोशिश की लेकिन वापसी त्रुटि:
यदि आप कर्सर से प्राप्त करना चाहते हैं तो आप इसके बजाय 'कर्सर.getString' क्यों नहीं कहते हैं। और आपकी छवि कहां संग्रहीत है? –