Using android DataBinding library how to pass parameters to binding events -
i followed examples android developers binding events , implementing step-by-step. working fine. want send parameters adapter handlers, how can achieve using data binding handlers
i got answer. in xml onclick use lambda expression
layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <data> <variable name="movie" type="embitel.com.databindingexample.helper.movie" /> <variable name="handler" type="embitel.com.databindingexample.helper.myhandlers" /> </data> <android.support.v7.widget.cardview android:id="@+id/cardview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margintop="4dp"
android:onclick="@{(view)->handler.onitemclicked(view,movie)}"
app:cardbackgroundcolor="@android:color/white" app:cardcornerradius="4dp"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="8dp"> <imageview android:layout_width="match_parent" android:layout_height="128dp" android:scaletype="centercrop" app:error="@{@drawable/ic_launcher}" app:imageurl="@{movie.imageurl}" /> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@{movie.title}" /> </linearlayout> </android.support.v7.widget.cardview>
then create handler class as,
public class myhandlers { public void onitemclicked(view v, movie movie) { context context = v.getcontext(); context.startactivity(detailactivity.buildintent(context, movie)); }
}
then need set handler xml iflated as,
binding.sethandler(new myhandlers());
you can put handler method in class. in case have set class name handler.
Comments
Post a Comment