I was wondering if there is a way to iterate through the resource file to get all of the images for the program and push them into an array??
If so how and what would be the simplest way of doing this?
I was wondering if there is a way to iterate through the resource file to get all of the images for the program and push them into an array??
If so how and what would be the simplest way of doing this?
You can accomplish this by using Reflection in java.
If you're not familiar with it already , here's a good starting point at programmcreek.com :
http://www.programcreek.com/2013/09/java-reflection-tutorial/
Simply put, as an example, you can use this sample code to iterate through R in your code :
import java.lang.reflect.Field;
import android.util.Log;
public class ResourceUtil {
/**
* Finds the resource ID for the current application's resources.
* @param Rclass Resource class to find resource in.
* Example: R.string.class, R.layout.class, R.drawable.class
* @param name Name of the resource to search for.
* @return The id of the resource or -1 if not found.
*/
public static int getResourceByName(Class<?> Rclass, String name) {
int id = -1;
try {
if (Rclass != null) {
final Field field = Rclass.getField(name);
if (field != null)
id = field.getInt(null);
}
} catch (final Exception e) {
Log.e("GET_RESOURCE_BY_NAME: ", e.toString());
e.printStackTrace();
}
return id;
}
Also, you may refer to this questions for more insight : Android: Programatically iterate through Resource ids