Android Form EditText Show Keyboard onResume
When my Activity is loaded, I wish the txtEdit EditText widget to get focus and show the keyboard.
I tried this in the onResume() but it does not automatically show.
@Override
protected void onResume() {
InputMethodManager mgr = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(txtSearch, InputMe开发者_运维技巧thodManager.SHOW_IMPLICIT);
This worked for me:
@Override
public void onResume() {
super.onResume();
if (mFirstTime) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mAdapter.prepareFocus(); // request the focus and show the softkeyboard here
}
}, 100);
}
mFirstTime = false;
}
精彩评论