Android 如何分配数据以在xml中包含布局?
假设我们有一个包含文本视图的布局:Android 如何分配数据以在xml中包含布局?,android,xml,layout,include,Android,Xml,Layout,Include,假设我们有一个包含文本视图的布局: <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
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>
然后多次包含此布局:
<include android:id="@+id/info1" layout="@layout/myLayout" />
<include android:id="@+id/info2" layout="@layout/myLayout" />
<include android:id="@+id/info3" layout="@layout/myLayout" />
是否可以将文本分配到包含这些布局的xml文件中的每个文本视图中?如果没有,那么如何在运行时分配?您可以,为此您需要确定您的布局
LinearLayout info1 = (LinearLayout)findViewById(R.id.info1);
然后,使用此布局对象,您需要标识您的TextView
TextView text1 = (TextView)info1.findViewById(R.id.text1);
text1.setText("Your text");