michaelmuenzer/ScrollableNumberPicker

Databinding support needed

tejasvih opened this issue · 0 comments

Support to databinding will be great!

I had to create a DataAdapter to overcome this.
Publishing here if anyone needs

public class ScrollableNumberPickerBindingAdapters {

    @BindingAdapter(value = "selectedValueAttrChanged")
    public static void setListener(com.michaelmuenzer.android.scrollablennumberpicker.ScrollableNumberPicker picker, final InverseBindingListener listener) {
        if (listener != null) {
            picker.setListener(new ScrollableNumberPickerListener() {
                @Override
                public void onNumberPicked(int value) {
                    listener.onChange();
                }
            });
        }
    }

    @BindingAdapter("selectedValue")
    public static void setSelectedValue(com.michaelmuenzer.android.scrollablennumberpicker.ScrollableNumberPicker picker, int value) {
        if (picker.getValue() != value) picker.setValue(value);
    }


    @InverseBindingAdapter(attribute = "selectedValue")
    public static int getSelectedValue(com.michaelmuenzer.android.scrollablennumberpicker.ScrollableNumberPicker picker) {
        return picker.getValue();
    }

}

Usage:

<com.michaelmuenzer.android.scrollablennumberpicker.ScrollableNumberPicker
android:id="@+id/picker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:selectedValue="@={item.Number}"
/>