开发者

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;

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜