Drawable Reference Store in Database
I have some ima开发者_StackOverflow社区ge names stored in a database (Fully Qualified Like R.drawable. SomeImageName) Column type is Integer, but the images themselves are in the /res/drawable folder of the application.
I need to assign these images to some views at runtime, and I'm currently doing it this way:
SomeView.setBackgroundResource(Cursor.getstring(Image_column_Index));
and
someView.setBackgroundResource(getResources().getIdentifier(cursor.getString(Image_Column_Index, null, null));
Neither of these methods are working. Thanks in advance.
for R.drawable.image_name try smthing like this
getResources().getIdentifier("image_name","drawable", getPackageName())
or use
getResources().getIdentifier("your.full.pakage.name:drawable/image_name",null,null);
精彩评论