问如何动态加载xml模板,并且实例化多个对象,就是id不一样怎么办?
模板保存文件为R.layout.item_view
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="left|center"
android:layout_weight="1" >
<CheckBox
android:id="@+id/checkbox_select"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
如下面xml模板,现在我想实例化多个xml布局和对象,但是android:id="@+id/checkbox_select"这个id要不同个怎么办啊?
如这样:LinearLayout layout_item = (LinearLayout)this.inflate(context, R.layout.item_view, null);就能实例化一个,然后this.add它就OK了。
但是我要实例化多个这样的布局,怎么弄啊?
如:LinearLayout layout_item1 = (LinearLayout)this.inflate(context, R.layout.item_view, null);
LinearLayout layout_item2 = (LinearLayout)this.inflate(context, R.layout.item_view, null);
LinearLayout layout_item3 = (LinearLayout)this.inflate(context, R.layout.item_view, null);
....
像上面实例化三个对象后,android:id="@+id/checkbox_select"都是相同的,就直接layout_item1.RelativeLayout.checkbox_select吗?
还想问,layout_item1对象实例化后,如何对checkbox_select进行访问?