Reputation: 21
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
Reputation: 3156
You can do this,
/**
* Use example:
* app:showDatePicker="@{null}"
*/
@BindingAdapter("showDatePicker")
fun TextView.showDatePicker(dummy: Any?) {
// ...
}
Upvotes: 3
Reputation: 59004
You can't have BindingAdapter
without any parameter. What you can do is to pass null.
Upvotes: 0