java - How do I create array of drawable automatically -
i have while loop create string array below
string[] imageid = {"r.drawable.img0","r.drawable.img1"};
but want store integer array
integer[] imageid = {r.drawable.img20,r.drawable.img1};
one way of doing without using reflection create mapping drawables have (since know drawables in resources @ compile time):
static final map<string, integer> mapping; static { final map<string, integer> tempmapping = new hashmap<>(); tempmapping.put("r.drawable.img0", r.drawable.img20); tempmapping.put("r.drawable.img1", r.drawable.img1); tempmapping.put([your other drawables]); mapping = collections.unmodifiablemap(valuesbyname); }
after that, depending on app's logic, construct array of drawables' names, , convert array of drawables' ids using map.
Comments
Post a Comment