I made a custom attribute for data binding which doesn't require any argument and all it does is that valides the TextinputEditText but I can't figure out a way to pass void parameter in the xml attribute.
This doesn't compile.
BindingAdapter.java
@BindingAdapter("app:validator")
public static void textValidator(TextInputLayout textInputLayout) {
doesSomething();
}
layout_file.xml
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:validator="@{ void }">
<android.support.design.widget.TextInputEditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"" />
</android.support.design.widget.TextInputLayout>
I've tried passing void or null in the xml but it just doesn't compile. I researched and found out that there should be atleast one or two value parameters in the method. So I could make it work by passing a parameter, let's say a boolean just for the sake of passing and not using it. For ex,
This one compiles. But it's just a hack, someone please suggest a better approach.
BindingAdapter.java
@BindingAdapter("app:validator")
public static void textValidator(TextInputLayout textInputLayout, boolean bl) {
doesSomething();
}
layout_file.xml
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:validator="@{ booleanVariable }">
<android.support.design.widget.TextInputEditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"" />
</android.support.design.widget.TextInputLayout>