My EditText is like this:
Ok, I've figured out the perfect solution after these days:
1. Create BindingAdapter Function:
object DataBindingUtil { //place in an util (singleton) class
@BindingAdapter("android:text", "isAddCase") //custom layout attribute, see below
@JvmStatic //required
fun setText(editText: EditText, text: String, isAddCase: Boolean) { //pass in argument
if (isAddCase) editText.setText("") else editText.setText(text)
}
}
BindingAdapter function:
How can I pass multiple arguments via xml for a custom setter when using Android data binding2. Apply Custom Attribute in View:
//here
BindingAdapter function is triggered only when using EditText and custom attribute At The Same Time.