0
我正在处理一个布局,该布局托管许多自定义视图。每个自定义视图都具有“myname:num”属性,该属性包含唯一数字值。android通过属性查找自定义视图
问题:如何通过“num”属性找到视图?通常我会使用findViewById()方法,但由于“android:id”不能是数字,我必须找到另一个解决方案。
布局定义:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myname="http://schemas.android.com/apk/res/com.example"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.example.custom.MyView
myname:num="17"
myname:type="2" />
<com.example.custom.MyView
myname:num="18"
myname:type="2" />
<com.example.custom.MyView
myname:num="19"
myname:type="2" />
</LinearLayout>
</LinearLayout>
你应该缓存所有这些,否则它会非常慢。 – rupps