I have these images in the drawable folder:
image_1.png
image_2.png
image_3.png
...
image_n.png
And I have a PlayerDTO that has an id attribute like this:
public class PlayerDTO implements Serializable {
private static final long serialVersionUID = 1L;
private int id;
//... getters and setters
}
I need to establish a match between the player id and it corresponding image to set it in an ImageView. e.g.:
player id = 1. It's image is image_1.png
player id = 2. It's image is image_2.png
...
player id = n. It's image is image_n.png
This is the same but this is not dynamically:
ImageView imageView = (ImageView) findViewById(R.id.image);
imageView.setImageResource(R.drawable.image_1);
How can I do this programmatically and dynamically?