If I have one layout file => res/layout/item.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="60dp"
>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="John"
/>
<TextView
android:id="@+id/age"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:text="29" />
</LinearLayout>
And I have another layout file whose content includes several of above item=> res/layout/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="60dp"
android:orientation="vertical"
>
<!--How can I override "name" and "age" attribute in the included item layout-->
<include android:id="@+id/student" layout="@layout/tem" />
<include android:id="@+id/teacher" layout="@layout/item" />
<include android:id="@+id/other" layout="@layout/item" />
</LinearLayout>
As you see above, I use <include>
tag to include the same layout. But, how can I override the "name
" and "age
" text value in the included item.xml from main.xml for each included item??
I hope this will work.
View v=(View)findviewbyid(R.id.student);
Textview name=(TextView)v.findviewbyid(R.id.name);
Textview age=(TextView)v.findviewbyid(R.id.age);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With