Multiple instances of included layout, namespacing question.

Skip to first unread message


Jan 12, 2010, 2:09:15 PM1/12/10
to Android Developers
I've been attempting to use the <include> tag in some layouts and it
seems that these are of limited use because of the flat namespace of
the approach.

Suppose I have a layout (attribs and xml namespace decl omitted for


<LinearLayout android:id="@+id/row" >
<ImageView android:id="@+id/image" />
<TextView android:id="@+id/text" />

Now include this twice inside a 'parent' view


<ViewFlipper android:id="@+id/flipper" >
<include android:id="@+id/row1" android:layout="component" />
<include android:id="@+id/row2" android:layout="component" />

Now in my java code I have a conundrum. I am not able to identify each
individual instance o f the children included layouts root view. In
the include tags I can replace the root id with "row1" and "row2" so
I can find the individual linear layouts using findViewById


LinearLayout row1 = (LinearLayout) findViewById(
LinearLayout row2 = (LinearLayout) findViewById(

However, I can't easily access the two instances of the TextView which
are children of row1 and row2 because all I have to play with is the
single id "text"


TextView text = (TextView) findViewById(;

In this case, which instance (row1.text or row2.text) does this refer
to, both of them, or none?

I guess I would need to use another means of accessing the children of
row1 and row2.

Anyone know how this can be done?

Romain Guy

Jan 12, 2010, 4:30:29 PM1/12/10
It's easy:

LinearLayout row1 = (LinearLayout) findViewById(

TextView text1 = row1.findViewById(;

LinearLayout row2 = (LinearLayout) findViewById(

TextView text2 = row2.findViewById(;

> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to
> To unsubscribe from this group, send email to
> For more options, visit this group at

Romain Guy
Android framework engineer

Note: please don't send private questions to me, as I don't have time
to provide private support. All such questions should be posted on
public forums, where I and others can see and answer them


Jan 12, 2010, 5:30:20 PM1/12/10
to Android Developers
Thanks Romain. I should have read the API docs rather than just the
dev guide, its pretty obvious from the docs for findViewById now that
I look at it.


Reply all
Reply to author
Message has been deleted
0 new messages