AnySoftKeyboad stays with garbage data after I hide it
I have a problem which occurs only when I use AnySoftKeyboard. I'm trying to show/hide the keyboard according to EditText focus. I used the methods I found in this post
When I'm hiding the keyboard, there is a strange behavior -
- When I rotate the screen, the text that was in the EditText is doubled.
- I thought that it has to do with the onCreate method, but I can see the it happens also when I click "back" (Finish()). I see it for a split second before the Activity is closed.
- When I start a new activity, (ActivityB from ActivityA) then clicking "Back" once doesn't do anything (probably "closing" the invisible keyboard).
- When I click "back" again, ActivityB closes but I can see for a split second the text from ActivityA keyboard in a big font across the screen (like a开发者_Go百科 100 millisecond pop-up )
Does anyone has an idea how to deal with it?
Apparently it is a bug in AnySoftKeyboard. I didn't happen when I use other keyboards.
I solved it by doing setText to the EditText view before hiding it - its probably resets some stuff on keyboard object.
Here is my code:
View view = getWindow().getCurrentFocus();
if (view==null)
return;
IBinder binder = view.getWindowToken();
if (binder == null)
return;
// I used this to fix the strange behaviour
if (view instanceof EditText)
((EditText)view).setText(((EditText)view).getText().toString());
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(binder, InputMethodManager.HIDE_NOT_ALWAYS);
Surprisingly it works!
Try this:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
精彩评论