radzio / android-data-binding-recyclerview

Using Recyclerview with the new Android Data Binding framework
Apache License 2.0
564 stars 97 forks source link

Click handling for items within a row #12

Open maberer opened 8 years ago

maberer commented 8 years ago

How can we detect, if a "firstName" or "lastName" is clicked? So generally: How can we detect which item has been clicked within a row item? This should consider CompositeItemBinder with different item types...

I am thinking about having

"firstNameClickHandler()" "lastNameClickHandler()"

in the activity?

edvaldeysteinsson commented 8 years ago

you could do this

Set this on the view you want to be clickable

android:onClick="firstNameClickHandler"
android:tag="@{user}" // the viewmodel variable

and then in your activity

public void firstNameClickHandler(View v) {
    UserViewModel userViewModel = (UserViewModel)v.getTag();
}