I am trying to get view in dispatchTouchEvent()
.
However, this only passes MotionEvent. It has x and y position. But, it doesn't pass view itself.
I can get view with currentFocus
. However, this gets view after having a focus. And when you touch EditText and then Outside of EdiText, EditText still has the focus. So, currentFocus
will be the same EditText.
What I am trying to do is closing keyboard when I touch non-EditText. And showing keybaord when I touch EditText. But when I touch EditText A and then EditText B, it shouldn't be blinking(hiding and showing again)
What I was trying is:
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
var view = currentFocus
if (view == null) {
view = View(this@BaseActivity)
}
ev?.let {
val isInRange = isRegionOfInterest(view, ev)
if(!isInRange){
hideKeyboard()
currentFocus?.clearFocus()
}
}
return super.dispatchTouchEvent(ev)
}
But this doesn't seem to be the right way. It'd be great if I can get a view with X and Y positon. Do you know any way to do that?