Reputation: 28188
Using the below layouts, getView(R.id.included).getView(R.id.text_view)
evaluates to null
. If I surround the TextView
in a LinearLayout
the problem disappears. What's going on here?
layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include android:id="@+id/included"
layout="@layout/included" />
</LinearLayout>
included.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/text_view"/>
Upvotes: 3
Views: 693
Reputation: 28188
<include>
isn't exactly well documented.
Tor Norbye wrote:
The <include>
tag is not a real view, so findByView
will not find it. The @id
attribute (and any other attributes you've set on the include tag) gets applied on the root tag of the included layout instead. So your activity.getView(R.id.included1)
should in fact be the <TextView>
itself.
Upvotes: 5