I hope you can help me, I already researched my case but didn\'t found a good answer. I want to compare the content of a variable with the names of all existing resources (i
Sorry, I know you were looking for a Java solution, but I did not find any solution for the C# and Xamarin issue in StackOverflow, so I will leave my solution for Android here if you don't mind.
I found a well written class ReflectionUtils in GitHub, just used it and made this method to call.
private List<string> GetAllStrings()
{
IEnumerable<FieldInfo> fields = ReflectionUtils.GetAllFields(typeof(Resource.String));
List<string> list = new List<string>();
using (var enumerator = fields.GetEnumerator())
{
try
{
while (enumerator.MoveNext())
{
list.Add(enumerator.Current.Name);
}
} catch (Exception e)
{
// Handle exception.
}
}
return list;
}
Or in other words: How to get a list (containing Strings) of all resource names, preferential only drawable resources?
This is probably what you want:
Field[] fields = R.drawable.class.getFields();
String[] allDrawablesNames = new String[fields.length];
for (int i =0; i < fields.length; i++) {
allDrawablesNames[i] = fields[i].getName();
}