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>

3
  • "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? Commented Jul 6, 2022 at 3:11
  • @TylerV added xml Commented Jul 6, 2022 at 5:31
  • 1
    Does this answer your question? Android Data Binding - Reference to view Commented Jul 6, 2022 at 11:25

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.