David Cheung David Cheung - 5 months ago 26
Android Question

cannot refer to other view id in Android databinding

I just finished watching Advanced Data Binding - Google I/O 2016 and would like to apply the following to reduce repetition of my expression used in different views.

enter image description here

But I cannot make it work in my case:

<ImageButton
android:id="@+id/btn_list"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="start"
android:background="@drawable/btn_s01_list"
android:visibility="@{bean.shouldHideControls? View.GONE: View.VISIBLE}"/>

<ToggleButton
android:id="@+id/btn_radar"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/btn_radar_selector"
android:checked="false"
android:gravity="end"
android:text=""
android:textOff=""
android:textOn=""
android:visibility="@{btn_list.visibility}"/>


and I got


Error:(426, 39) Identifiers must have user defined types from the XML
file. btn_list is missing it

Answer

You may need to change the following line:

android:visibility="@{btn_list.visibility}"/>

To:

android:visibility="@{btnList.visibility}"/>

Check this answer for an explanation.

Comments