I'm working on an Android project, and i have a lot of drawables. These drawables are all named like icon_0.png
, icon_1.png
... icon_100.png
. I want to add all the resource id's of these drawables to an ArrayList of Integers. (For those, who do not know android, only Java, i am talking about static variables, in a static inner class of a class, like R.drawable.icon_0
. All of this static variables are Integers.)
Is there a more efficient way to do this, than adding them one by one? Like
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(R.drawable.icon_1);
list.add(R.drawable.icon_2);
...
list.add(R.drawable.icon_100);
Can i loop through them somehow? Like
for(int i=0; i<100; i++)
{
list.add(R.drawable.icon_+i); //<--- I know this doesn't work.
}
I have no control over the file where these static integers are, and i cannot create the drawables in runtime.
Any help would be appreciated!
EDIT
Okay, i read the answers, but i have one major problem: I don't have access to any Context
instances where i need to create this array/list of ids (i do it in a static initialzer block), so the getResources() method, what two of the answers suggested wont work. Is there any other way of doing this?