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"/>
<include>
isn't exactly well documented.Tor Norbye wrote:
The
<include>
tag is not a real view, sofindByView
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 youractivity.getView(R.id.included1)
should in fact be the<TextView>
itself.