分享一个android的工具类(扩充根据R类中的id寻址xml)
2010-11-05 00:56:48 来源:WEB开发网android提供的根据id找简单资源如下
Java代码
String about = getString(R.string.about);
String[] aryShop = getResources().getStringArray(R.array.level);
String about = getString(R.string.about);
String[] aryShop = getResources().getStringArray(R.array.level);
分享一个自己扩充的可以针对性的选个多个ID资源
Java代码
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));
}
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){//与
更多精彩
赞助商链接