Issue
How can I do something like this?
for(String name: nameArray){
ImageView i = new ImageView(this);
// the line below does not work of course
i.setBackgroundImage(R.drawable.name);
//do some stuff
}
I've searched up some solutions but most of them involves integer IDs which I do not have
Solution
Could you please check the code below?
I'm not totally sure if it works.. However, I know that you can use Resources.getIdentifier()
which returns the ID. However, I'm not sure if it works with drawable
as well.
for(String name: nameArray){
ImageView i = new ImageView(this);
i.setBackgroundImage(getResources().getIdentifier(name, "drawable", getPackageName()));
}
Answered By - W0rmH0le
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.