tags:

views:

180

answers:

3

Hi,

In my layout xml file, I have included other layout xml file (each with a different android id).

But when I run it in the emulator, and start Hierarchy Viewer, each of the layout still shows 'NO_ID', and in my code, I have findViewById(R.id.test1) and findViewById(R.id.test2) both returns null.

Can anyone please help me with my problem? Thank you.

A: 

AFAIK, <include> ignores the android:id attribute. Bear in mind that the purpose behind <include> is to share layout fragments between layout files, not to repeat the same layout fragment multiple times within a single layout.

CommonsWare
A: 

Romain Guy indicates that you can override the ID of an included layout by putting an android:id attribute inside the <include> tag.

<include android:id="@+id/cell1" layout="@layout/workspace_screen" />
Daniel Yankowsky
A: 

Specify the ID in the <include>

<include layout="@layout/test" android:id="@+id/test1" />

Then use two findViewById to access fields in the layout

View test1View = findViewById(R.id.test1);
TextView test1TextView = (TextView) test1View.findViewById(R.id.text);

Using that approach, you can access any field in any include you have.

Ron Romero