0

I am trying to reference a view in the xml as such:

<Button
android:id="@+id/button"
android:onClick="@{(v) -> events.userClicked(another_layout_id)}"
.
.
.
android:text="Click me
/>"

where events is a variable and userClicked() is a function that accepts a view and another_layout_id is another View in the xml layout that button is in (though not same hierachy).

According to the top answer here: Pass another view as parameter in data binding, I should be able to reference another_layout_id but I am receiving a "cannot find identifier" error. Any idea why this is?

EDIT: Added XML code:

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data>

        <variable
            name="state"
            type="bindingModel" />

        <variable
            name="events"
            type="DataModel" />

    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
    >

     <TextView
      android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="label"/>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/another_layout_id"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
           >

            <androidx.constraintlayout.helper.widget.Flow
                android:id="@+id/flow_layout"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                app:flow_horizontalGap="8dp"
                />

        </androidx.constraintlayout.widget.ConstraintLayout>

        <Button
            android:id="@+id/show_all"
            style="@style/TextButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="@{(v) -> 
            events.userClicked(another_layout_id)}"
            android:text="Click me" />
            
    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

Gil Ong
  • 67
  • 1
  • 6
  • "though not same hierachy" could be important. Can you show in the question where the view you are referencing is? Is it nested in an included XML? Or in another activity or something entirely separate? – Tyler V Jul 06 '22 at 03:11
  • @TylerV added xml – Gil Ong Jul 06 '22 at 05:31
  • 1
    Does this answer your question? [Android Data Binding - Reference to view](https://stackoverflow.com/questions/38077736/android-data-binding-reference-to-view) – Tyler V Jul 06 '22 at 11:25

1 Answers1

0

Duplicate of Android Data Binding - Reference to view, I had to refer to the view id in camelCase as opposed to the snake case.

Gil Ong
  • 67
  • 1
  • 6