У меня есть файл main.xml, описывающий макет моей основной деятельности:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include layout="@layout/mylayout" />
<include layout="@layout/mylayout" />
<include layout="@layout/mylayout" />
<include layout="@layout/mylayout" />
<include layout="@layout/mylayout" />
<include layout="@layout/mylayout" />
</LinearLayout>
и его включенный макет xml файла (mylayout.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mylayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello world" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Я просто хочу включить "mylayout" в свой основной макет 5 раз, но вместо того, чтобы видеть "привет мир" 5 раз, я хочу, чтобы TextView содержал пользовательский текст.
Есть ли способ сделать это, установив некоторый атрибут элемента include, чтобы переопределить текст Text Text для детей? Каким будет наилучший подход для достижения этого?