Issue
I try to detect when editText loss focus. I use DataBinding and my code doesn't work. I use custom listener EditTextFocusListener
because my EditText has another listen adapter. There is no callback from setOnFocusChangeListener
@JvmStatic
@BindingAdapter("onFocusAction")
fun onFocusAction(view: EditText, editTextFocusListener: EditTextFocusListener) {
view.setOnFocusChangeListener { view, hasFocus ->
if(!hasFocus){
editTextFocusListener.lossFocus("loss focus")
}
}
}
<EditText
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:resolveKeyboardInputType="@{model.inputTypeBind}"
app:afterTextChanged="@{(text) -> model.inputBind.onTextChanged()}"
app:requestKeyboard="@{model.inputBind.requestKeyboardBind}"
app:requestKeyboardModel="@{model.inputBind}"
app:onKeyboardDoneAction="@{() -> model.onDoneAction.invoke()}"
app:onFocusAction="@{(loss) -> model.onFocusAction.invoke(loss)}"
app:text="@={model.inputBind.textBind}"/>
Solution
You can use OnFocusChangeListener For example:
override fun onFocusChange(view: View?, hasFocus: Boolean) {
if (!hasFocus)
//do something (lossed focus)
}
Answered By - Huseynbaba
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.