Reputation: 416
I want to loop through ten Drawable resources named ab1, ab2 ab3,ab4,ab5 etc. and call a function on them.
b = decodeSampledBitmapFromResource(getResources(), R.drawable.ab1, reqHeight, reqWidth);
i am looking for something like this.
for(int i =1; i<11; i++)
{
b = decodeSampledBitmapFromResource(getResources(), R.drawable.ab[j], reqHeight, reqWidth);
}
How would I do that?
Upvotes: 0
Views: 595
Reputation: 614
I am not well experienced in android but in Java SE I put every object in a java.util.Vector and iterate over the vector elements.
Maybe some like this
for(int i =1; i<11; i++) {
b = someMethod(getResources(), vectorDrawables.elementAt(i), reqHeight, reqWidth);
}
I just cant remember how to add a GUI element to a vector.
Upvotes: 0
Reputation: 7079
You can put those objects in list
list.add(R.drawable.ab1);
list.add(R.drawable.ab2);
list.add(R.drawable.ab3);
list.add(R.drawable.ab4);
.
.
.
and then you can iterate through that list, using list.get(i)
and pass each object in the method.
for(int i =1; i<11; i++)
{
b = decodeSampledBitmapFromResource(getResources(),list.get(i), reqHeight, reqWidth);
}
Upvotes: 4