I can do this programatically, but i want to know best approach using android databinding
.
Here is my xml layout. I want to increase or decrease int value onClick
of some button. I don't want handle click in activity class. Is this possible, if yes.
In below layout you can see an Integer value count. Value count should be changed on click of Button.
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="android.view.View"/>
<variable
name="activity"
type="com.amelio.ui.activities.ActivityProductDetail"/>
<variable
name="count"
type="Integer"/>
</data>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="@{() -> count++}"
android:text="Less"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@{`` + count}"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/ivBtnPlus"
android:onClick="@{() -> count--}"
android:text="Add"
/>
</LinearLayout>
</layout>