把设置的方法放在一个方法里面,然后把Id当做参数传进去,比如R.id.text1的话,可以这样用一个变量String
baseId="R.id.",这个方法可以写成setConfig(String
strId){String
currentId=baseId+strId;
//后面的代码按下面来
}
然后再用下面的方法
public
static
int
getResourdIdByResourdName(Context
context,
String
ResName){
int
resourceId
=
0;
try
{
Field
field
=
R.drawable.class.getField(ResName);
field.setAccessible(true);
try
{
resourceId
=
field.getInt(null);
}
catch
(IllegalArgumentException
e)
{
log.showLogDebug("IllegalArgumentException:"
+
e.toString());
}
catch
(IllegalAccessException
e)
{
log.showLogDebug("IllegalAccessException:"
+
e.toString());
}
}
catch
(NoSuchFieldException
e)
{
log.showLogDebug("NoSuchFieldException:"
+
e.toString());
}
return
resourceId;
}将currentId作为参数传入就可以了,这时在调用findViewById找,,,
采纳啊,大哥,写了这么多
温馨提示:答案为网友推荐,仅供参考