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?
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
精彩评论