how to assign data to include layout in xml?
Assume we have a layout contains a TextView:
<LinearLayout
开发者_开发百科xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/text1"
style="@style/text_style"/>
</LinearLayout>
and then include this layout several times:
<include android:id="@+id/info1" layout="@layout/myLayout" />
<include android:id="@+id/info2" layout="@layout/myLayout" />
<include android:id="@+id/info3" layout="@layout/myLayout" />
Is it possible to assign text into each TextView in the xml file which contains these layouts?
If not, then how to assign in runtime?You can, For this you need to identify you layout
LinearLayout info1 = (LinearLayout)findViewById(R.id.info1);
Then with this layout object you need to identify you TextView
TextView text1 = (TextView)info1.findViewById(R.id.text1);
text1.setText("Your text");
精彩评论