android提供的根据id找简单资源如下
String about = getString(R.string.about);
String[] aryShop = getResources().getStringArray(R.array.level);
分享一个自己扩充的可以针对性的选个多个ID资源
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<drawable> innerClass) throws IllegalArgumentException, IllegalAccessException {
List<Integer> result=new ArrayList<Integer>();
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<drawable> innerClass,String fileNameLikse,Boolean andor) throws IllegalArgumentException, IllegalAccessException {
if(fileNameLikse==null || andor==null){
return readId(innerClass);
}
List<Integer> result=new ArrayList<Integer>();
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){
for (int i = 0; i < ii.length; i++) {
System.out.println(ii[i]);
}
}
}
}
贴下我的R
package lidongbo.test;
public final class R {
public static final class array {
public static final int level=0x7f050000;
}
public static final class attr {
}
public static final class drawable {
public static final int blue=0x7f02000b;
public static final int brown=0x7f02000e;
public static final int darkgray=0x7f020007;
public static final int darkgreen=0x7f02000d;
public static final int dreamweaver=0x7f020000;
public static final int flash=0x7f020001;
public static final int icon=0x7f020002;
public static final int illustrator=0x7f020003;
public static final int indesign=0x7f020004;
public static final int lightroom=0x7f020005;
public static final int photoshop=0x7f020006;
public static final int pink=0x7f02000c;
public static final int translucent_background=0x7f02000a;
public static final int transparent_background=0x7f020009;
public static final int white=0x7f020008;
}
public static final class id {
public static final int age=0x7f070012;
public static final int food_relativelayout=0x7f070000;
public static final int food_text_explanation=0x7f070002;
public static final int food_text_question=0x7f070001;
public static final int height=0x7f070013;
public static final int interim_button_submit=0x7f07000c;
public static final int interim_text_text1=0x7f070009;
public static final int interim_text_text2=0x7f070008;
public static final int interim_text_text3=0x7f070007;
public static final int interim_text_text4=0x7f070006;
public static final int interim_text_text5=0x7f07000a;
public static final int interim_text_text6=0x7f07000b;
public static final int interim_text_text7=0x7f070005;
public static final int interim_text_title=0x7f070004;
public static final int myGallery=0x7f070023;
public static final int name=0x7f070011;
public static final int next_button_back=0x7f07001d;
public static final int next_button_submit=0x7f07001c;
public static final int next_edittext_circumference=0x7f07001e;
public static final int next_edittext_hipcircumference=0x7f070020;
public static final int next_edittext_waistline=0x7f07001f;
public static final int next_text_text1=0x7f070018;
public static final int next_text_text3=0x7f070016;
public static final int next_text_text4=0x7f070019;
public static final int next_text_text5=0x7f07001a;
public static final int next_text_text6=0x7f07001b;
public static final int next_text_title=0x7f070015;
public static final int result_relativelayout=0x7f070021;
public static final int result_text_result=0x7f070022;
public static final int sex=0x7f07000d;
public static final int sex1=0x7f07000e;
public static final int sex2=0x7f07000f;
public static final int sex3=0x7f070010;
public static final int text2=0x7f070017;
public static final int weight=0x7f070014;
public static final int widget0=0x7f070003;
}
public static final class layout {
public static final int food=0x7f030000;
public static final int interim=0x7f030001;
public static final int main=0x7f030002;
public static final int next=0x7f030003;
public static final int result=0x7f030004;
}
public static final class string {
public static final int about=0x7f040006;
public static final int about_msg=0x7f040008;
public static final int age=0x7f040010;
public static final int app_name=0x7f040001;
public static final int back=0x7f040015;
public static final int choose=0x7f04002b;
public static final int circumference=0x7f040012;
public static final int exit=0x7f040007;
public static final int food_fruits=0x7f040016;
public static final int food_fruits_apple=0x7f040019;
public static final int food_fruits_banana=0x7f04001a;
public static final int food_fruits_orange=0x7f04001b;
public static final int food_fruits_peach=0x7f04001c;
public static final int food_fruits_pear=0x7f04001e;
public static final int food_fruits_watermelon=0x7f04001d;
public static final int food_meat=0x7f040017;
public static final int food_meat_all=0x7f040027;
public static final int food_vegetables=0x7f040018;
public static final int food_vegetables_cabbage=0x7f040026;
public static final int food_vegetables_chili=0x7f040022;
public static final int food_vegetables_chineseCabbage=0x7f040023;
public static final int food_vegetables_guineaSquash=0x7f04001f;
public static final int food_vegetables_kidneyBean=0x7f040020;
public static final int food_vegetables_potato=0x7f040021;
public static final int food_vegetables_radish=0x7f040024;
public static final int food_vegetables_tomato=0x7f040025;
public static final int height=0x7f040003;
public static final int hello=0x7f040000;
public static final int hip_circumference=0x7f040013;
public static final int iKnow=0x7f040028;
public static final int name=0x7f040014;
public static final int ok=0x7f040009;
public static final int sex=0x7f040002;
public static final int sex1=0x7f04000c;
public static final int sex2=0x7f04000d;
public static final int sex3=0x7f04000e;
public static final int style1=0x7f040004;
public static final int style2=0x7f040005;
public static final int style3=0x7f04000b;
public static final int submit=0x7f04000a;
public static final int turn=0x7f04002a;
public static final int waistline=0x7f040011;
public static final int wait=0x7f040029;
public static final int weight=0x7f04000f;
}
public static final class style {
public static final int Style1=0x7f060000;
public static final int Style2=0x7f060001;
public static final int Style3=0x7f060002;
public static final int Theme=0x7f060003;
public static final int Theme_Translucent=0x7f060004;
}
}
分享到:
相关推荐
RFC955 朝向一个处理过程应用的传输服务 RFC962 TCP-4 的最初 RFC968 “这是开动前的黑暗” RFC974 邮件路由与域名系统 RFC975 自治联邦 RFC976 UUCP 邮件互换格式标准 RFC985 Internet 网关要求 - 起草 RFC988 主机...
RFC955_朝向一个处理过程应用的传输服务 RFC962_TCP-4 的最初 RFC968 “这是开动前的黑暗” RFC974_邮件路由与域名系统 RFC975_自治联邦 RFC976 UUCP 邮件互换格式标准 RFC985 Internet 网关要求 - 起草 RFC988 ...
RFC955 朝向一个处理过程应用的传输服务 RFC962 TCP-4 的最初 RFC968 “这是开动前的黑暗” RFC974 邮件路由与域名系统 RFC975 自治联邦 RFC976 UUCP 邮件互换格式标准 RFC985 Internet 网关要求 - 起草 RFC988 主机...
6.6 选择一个域名服务器 52 6.7 名字服务解析过程 52 6.7.1 递归查询 52 6.7.2 叠代查询 52 6.8 高速缓存 52 6.9 反向解析(Pointer)查询 52 6.10 DNS安全 52 6.11 资源记录 53 6.12 小结 54 第7章 WINS 55 7.1 ...
6.6 选择一个域名服务器 52 6.7 名字服务解析过程 52 6.7.1 递归查询 52 6.7.2 叠代查询 52 6.8 高速缓存 52 6.9 反向解析(Pointer)查询 52 6.10 DNS安全 52 6.11 资源记录 53 6.12 小结 54 第7章 WINS 55 7.1 ...
6.6 选择一个域名服务器 52 6.7 名字服务解析过程 52 6.7.1 递归查询 52 6.7.2 叠代查询 52 6.8 高速缓存 52 6.9 反向解析(Pointer)查询 52 6.10 DNS安全 52 6.11 资源记录 53 6.12 小结 54 第7章 WINS 55 7.1 ...
6.6 选择一个域名服务器 52 6.7 名字服务解析过程 52 6.7.1 递归查询 52 6.7.2 叠代查询 52 6.8 高速缓存 52 6.9 反向解析(Pointer)查询 52 6.10 DNS安全 52 6.11 资源记录 53 6.12 小结 54 第7章 WINS 55 7.1 ...
6.6 选择一个域名服务器 52 6.7 名字服务解析过程 52 6.7.1 递归查询 52 6.7.2 叠代查询 52 6.8 高速缓存 52 6.9 反向解析(Pointer)查询 52 6.10 DNS安全 52 6.11 资源记录 53 6.12 小结 54 第7章 WINS 55 7.1 ...
IP网络中的名字和地址 29 4.1 IP寻址 29 4.1.1 二进制和十进制数 30 4.1.2 IPv4地址格式 30 4.2 子网的出现 34 4.2.1 分子网 35 4.2.2 可变长子网掩码(VLSM) 37 4.3 无类域前路由(CIDR) 38 ...