Recently while developing an app, I faced an issue. I have searched a lot on google but couldn't find any solution. In the end I came across this Android issue tracker
To explain my issue, I have made a sample App.
Basic Working of my Sample App
What I want to achieve
How I am achieving this
wasEditing = true
.wasEditing = true
.wasEditing
and if it is true, I request focus for EditText. imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT,resultRec)
Where I am getting problem
Sometimes after executing this call, Keyboard is not visible in few cases, like during orientation change.
When I put logs I have found this function is returning false
But if I make this showSoftInput()
call with some delay of 100ms using mEditText.postDelayed()
in onResume()
everything works fine.
Question In what cases this function returns false and why delay is working?
Note Although I have solved my problem using delay, but I still want to know why it is behaving like that.
This is a problem I ran into today as well. Of my 8 android devices only 1 has the problem and it's running Android 4.0.4.
The problem was fixed by adding
mEditText.requestFocus();
mEditText.requestFocusFromTouch();
before calling mEditText.showSoftInput(...)
You'll see the resultcode
from showSoftInput
is now true
. I noticed that after the mEditText.requestFocus()
the isFocused()
was still false
. Probably a bug in Android 4.0 and perhaps 4.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With