Jegan Umapathy
Jegan Umapathy

Reputation: 21

Invoke binding adapter without any value

Just wanted way to invoke Binding Adapter without any value in xml.

Example :

XML

<android.support.v7.widget.AppCompatSpinner
                            android:id="@+id/spinner"
                            android:layout_width="match_parent"
                            android:layout_height="@dimen/spinner_height"
                            android:background="@drawable/background"
                            app:performClickOnFocus="@{true}"/>

BindingAdater Code

 @BindingAdapter({"app:performClickOnFocus"})
    public static void performClickOnSpinner(final AppCompatSpinner spinner, boolean arg) {
        spinner.setOnFocusChangeListener((v, hasFocus) -> {
            if (hasFocus) {
                spinner.performClick();
            }
        });
    }

Expected code should be without the boolean value.

Like below

 @BindingAdapter({"app:performClickOnFocus"})
    public static void performClickOnSpinner(final AppCompatSpinner spinner) {
        spinner.setOnFocusChangeListener((v, hasFocus) -> {
            if (hasFocus) {
                spinner.performClick();
            }
        });
    }

let me know is there any other way to achive this

Upvotes: 2

Views: 992

Answers (2)

Mahmudul Hasan Shohag
Mahmudul Hasan Shohag

Reputation: 3156

You can do this,

/**
* Use example:
* app:showDatePicker="@{null}"
*/
@BindingAdapter("showDatePicker")
fun TextView.showDatePicker(dummy: Any?) {
    // ...
}

Upvotes: 3

Khemraj Sharma
Khemraj Sharma

Reputation: 59004

You can't have BindingAdapter without any parameter. What you can do is to pass null.

Upvotes: 0

Related Questions