I need help to count how many pictures in drawable with criteria substring filename? like how many pictures with filename starting "SC" ?
Asked
Active
Viewed 1,283 times
1
-
1Great then, go ahead and try. – InnocentKiller Apr 01 '14 at 08:19
-
check this link http://stackoverflow.com/questions/3221603/android-retrieving-all-drawable-resources-from-resources-object – umerk44 Apr 01 '14 at 08:21
-
You want to count particular pictures with starting some name.. Then use `Asset` instead of Drawables. – user370305 Apr 01 '14 at 08:24
-
Also look at this one http://www.anddev.org/viewtopic.php?t=575 – user370305 Apr 01 '14 at 08:25
2 Answers
1
You can use reflection for that. Simply use getDeclaredFields()
to get all fields of R.drawable.class
. Then, just loop through them, look for the search term in the field names and get the drawable using Resources.getDrawable(Field.getInt());
.

FD_
- 12,947
- 4
- 35
- 62
0
Well,
I haven't tried it but you can use getFields() to get all the variables
R.drawable.class.getFields()
Then you can perform your search for specific file name accordingly.
See this to know more for Reflections in Java: http://www.ibm.com/developerworks/library/j-dyn0603/

Akshit Arora
- 428
- 3
- 15