分享一个android的工具类(扩充根据R类中的id寻址xml)
2010-11-05 00:56:48 来源:WEB开发网StringTokenizer st=new StringTokenizer(fileNameLikse,",| ");
while(st.hasMoreElements()){
if(!filedName.contains(st.nextElement().toString())){
continue LOODFILED;
}
}
result.add(fileds[i].getInt(innerClass));
System.out.println(filedName);
}else{//或
StringTokenizer st=new StringTokenizer(fileNameLikse,",| ");
while(st.hasMoreElements()){
if(filedName.contains(st.nextElement().toString())){
result.add(fileds[i].getInt(innerClass));
System.out.println(filedName);
continue LOODFILED;
}
}
}
}
return result.toArray(new Integer[0]);
}
public static void main(String[] args){
Integer[] ii=null;
try {
ii = ReadR.readId(R.drawable.class,"d,r",true);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if(ii!=null){
for (int i = 0; i < ii.length; i++) {
System.out.println(ii[i]);
}
}
}
}
package lidongbo.util;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import lidongbo.test.R;
import lidongbo.test.R.drawable;
/**
*
* @author lidongbo
*
*/
public class ReadR {
public static Integer[] readId(Class innerClass) throws IllegalArgumentException, IllegalAccessException {
List result=new ArrayList();
Field[] fileds = innerClass.getDeclaredFields();
for (int i = 0; i < fileds.length; i++) {
result.add(fileds[i].getInt(innerClass));
更多精彩
赞助商链接