开发者

I have an array contains string values, in that same name i have image in drawable.so i want to add in integer array how to do that?

开发者 https://www.devze.com 2023-03-06 06:28 出处:网络
I have an array contains string values, in that same name i have image in drawable.so i want to add in integer array how to do that? ex string newarray[]={\"jj\",\"kk\",\"ll\"};

I have an array contains string values, in that same name i have image in drawable.so i want to add in integer array how to do that? ex string newarray[]={"jj","kk","ll"}; i want to access R.d开发者_如何学运维rawable.jj ,R.drwable.kk,R.drawable.ll


To access the drawables you need an int. Instead of saving the names in a String array, save the IDs in an int array:

int[] drawables = {R.drawable.jj, R.drawable.kk, R.drawable.ll};

Then all you need to do to access them is call:

getResources().getDrawable(drawables[0]);


You could try to get the identifier by name:

Resources res = getResources();
res.getDrawable(res.getIdentifier(myStringArray[0], "drawable", myPackage));

A similar question was already answered: get resource id by passing name as a parameter in android

0

精彩评论

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

关注公众号