Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<include> tag override attribute

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??

like image 637
Leem.fin Avatar asked Nov 14 '22 09:11

Leem.fin


1 Answers

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);
like image 175
Sam Avatar answered Nov 16 '22 02:11

Sam