EditText in ListView with windowSoftInputMode adjustPan
I have a ListView
with an EditText
in each row. I have set windowSoftInputMode
to adjustPan
in the manifest for this activity, so when I tap on an EditText
the layout pans so that it is visible above the keyboard.
This works the first time I tap on an EditText
. But if I hit the back button to dismiss the keyboard, then tap the same EditText again (without tapping anything else, so the cursor re开发者_JAVA百科mains in the first EditText
), the keyboard comes back up but the layout does not pan this time. The result of this is that the EditText
is obscured behind the keyboard.
Has anyone experienced this behaviour / knows how to solve it?
Thanks
Still not sure why this happens, but I have a solution.
I have subclassed EditText
and overridden the method onKeyPreIme(int keyCode, KeyEvent event)
as follows:
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK)
{
clearFocus();
}
return super.onKeyPreIme(keyCode, event);
}
Now when the back key is pressed, the EditText
gives up focus. Then tapping it again has the desired behaviour.
精彩评论