开发者

Drawable Reference Store in Database

开发者 https://www.devze.com 2023-03-12 19:03 出处:网络
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

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消