分享一个android的工具类(扩充根据R类中的id寻址xml)
2010-11-05 00:56:48 来源:WEB开发网}
return result.toArray(new Integer[0]);
}
/**
* ,|空格 分割
* @param innerClass
* @param fileNameLikse
* @param andor true 与条件
* @return
* @throws IllegalArgumentException
* @throws IllegalAccessException
*/
public static Integer[] readId(Class innerClass,String fileNameLikse,Boolean andor) throws IllegalArgumentException, IllegalAccessException {
if(fileNameLikse==null || andor==null){
return readId(innerClass);
}
List result=new ArrayList();
Field[] fileds = innerClass.getDeclaredFields();
LOODFILED:for (int i = 0; i < fileds.length; i++) {
String filedName=fileds[i].getName();
if(andor){//与
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){
更多精彩
赞助商链接