Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 remains 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

like image 337
Matt Colliss Avatar asked Feb 10 '11 14:02

Matt Colliss


1 Answers

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.

like image 172
Matt Colliss Avatar answered Nov 01 '22 04:11

Matt Colliss