To draw on a canvas I need to get the image file from the resources like this:
bmpNode = BitmapFactory.decodeResource(getResources(), R.drawable.node);
After that i can call my canvas to draw:
c.drawBitmap(bmpNode, xPos, yPos, null);
The Problem is that I have a large amount of unique Node-objects with ID's as a String value. I numbered them from "1" to "100". Each node has its own image file in the resources also called "1" - "100". The way I know, I'd had to do a hundred lines of code to get every image:
1 = BitmapFactory.decodeResource(getResources(), R.drawable.1);
2 = BitmapFactory.decodeResource(getResources(), R.drawable.2);
[...]
100 = BitmapFactory.decodeResource(getResources(), R.drawable.100);
Now instead of putting 100 lines of code for each Image I would like to make a loop, witch would function something like the following code:
for (int i=0; i<arrayNodes.length; i++){ //for every Node in the Array
"i" = BitmapFactory.decodeResource(getResources(), R.drawable."i");
}
I was trying to look into reflection and maps, but I am new to this kind of problem and couldn't apply anything I found. Also I have no idea how to properly search for this problem, because I don't know what the input value for the method "R.drawable" is called.