dynamically obtain the int value of r file and dynamically get the int value of R.ARRAY.XXX by String-array Name property
Copy Code code as follows:
To dynamically get the int value of R.ARRAY.XXX through the String-array Name property
Public charsequence[] Getlistdata (String name) {
try {
class<?> Arrayclass = Getarrayresource (). GetClass ();
Field Intfield = Arrayclass.getfield (name);
int SourceID = intfield.getint (name);
Return Getresources (). Gettextarray (SourceID);
catch (Exception e) {
E.printstacktrace ();
}
return null;
}
Private Object arrayresource = null;
Private Object Getarrayresource () {
if (Arrayresource = = null) {
class<?> resource = R.class;
try {
class<?>[] classes = resource.getclasses ();
for (class<?> c:classes) {
int i = C.getmodifiers ();
String className = C.getname ();
String s = modifier.tostring (i);
if (S.contains ("static") && Classname.contains ("array")) {
Return C.getconstructor (). newinstance ();
} else {
Continue
}
}
catch (Exception e) {
E.printstacktrace ();
}
}
return arrayresource;
}