Добавить BindingAdapter
для setOnEditorActionListener
class ViewModel {
private val editorActionListener: TextView.OnEditorActionListener
init {
this.editorActionListener = TextView.OnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
// do your search logic
true
} else false
}
}
companion object {
@BindingAdapter("onEditorActionListener")
fun bindOnEditorActionListener(editText: EditText, editorActionListener: TextView.OnEditorActionListener) {
editText.setOnEditorActionListener(editorActionListener)
}
}
}
и используйте его в своем xml
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:padding="10dp"
android:text="@{viewModel.text}"
android:hint="@string/edit_text_hint"
android:imeOptions="actionSearch"
app:onEditorActionListener="@{viewModel.editorActionListener}"/>