Well, I got an EditText on my adapter that I want to clear his focus when I press button back of the soft-key bar. But the problem is: it just works if I hold that button and not when I make it quickly. What am I supposed to do? Here's the code:
holder.comprimento.setOnKeyListener(View.OnKeyListener { v, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_BACK) {
v.clearFocus()
return@OnKeyListener true
}
false
})
Use KeyEvent.KEYCODE_DEL instead of KeyEvent.KEYCODE_BACK.
UPDATE KeyEvent will be triggered only with softkeyboard. https://developer.android.com/reference/android/view/View.OnKeyListener