
把设置的方法放在一个方法里面,然后把Id当做参数传进去,比如Ridtext1的话,可以这样用一个变量String
baseId="Rid",这个方法可以写成setConfig(String
strId){String
currentId=baseId+strId;
//后面的代码按下面来
}
然后再用下面的方法
public
static
int
getResourdIdByResourdName(Context
context,
String
ResName){
int
resourceId
=
0;
try
{
Field
field
=
RdrawableclassgetField(ResName);
fieldsetAccessible(true);
try
{
resourceId
=
fieldgetInt(null);
}
catch
(IllegalArgumentException
e)
{
logshowLogDebug("IllegalArgumentException:"
+
etoString());
}
catch
(IllegalAccessException
e)
{
logshowLogDebug("IllegalAccessException:"
+
etoString());
}
}
catch
(NoSuchFieldException
e)
{
logshowLogDebug("NoSuchFieldException:"
+
etoString());
}
return
resourceId;
}将currentId作为参数传入就可以了,这时在调用findViewById找,,,
采纳啊,大哥,写了这么多
android 获取XML文件有几种方式 1R文件名文件里的数据名
2gentRu
3如果在控件属性那直接引用就行
直接用getsystemservice获取到windowmanager 。
IApplicationTokenaidl
IOnKeyguardExitResultaidl
IRotationWatcheraidl
IWindowaidl
IWindowManageraidl
WindowManageraidl
以上文件
当然找不到了!因为现在你添加的是settingxml,所以这个ImageView会默认在settingxml里找,settingxml里没有所以找不到;解决办法是你必须通过settingxml把preference_imagexml加载(inflate)进来,如:
LayoutInflater inflater = getLayoutInflater();
View imageLayout = inflaterinflate(Rlayoutpreference_imagexml,null);然后
ImageView imageView = (ImageView) imageLayoutfindViewById(RidRightImage);
这只是大致步骤,具体看你的程序
一个layout就是一个容器,你可以放一些子控件,当你要 *** 作子控件的时候,你就需要找对应的子控件,再去 *** 作它( *** 作比如设置字体,颜色,样式等)。
可以通过findViewById()方法 来获取,前提是,你的子控件需要定义一个id,然后在通过该方法来寻找并 *** 作它。
还可以通过findViewWithTag()方法来找到子控件(前提是你第一次找到这个子控件时,并设置一个tag),该方法一般用在activity调用adapter里面填充布局里面的子控件。
以上就是关于android怎么样获取当前activity下所有的textview控件全部的内容,包括:android怎么样获取当前activity下所有的textview控件、android开发中,在activity中如何获取xml中控件的属性、android的反射机制具体到android.view.IWindowManager该怎么用等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)