2010-08-15 70 views
1

当我的活动加载时,我希望txtEdit EditText小部件获得焦点并显示键盘。Android Form EditText显示键盘onResume

我在onResume()中试过这个,但它不会自动显示。

@Override 
protected void onResume() { 
    InputMethodManager mgr = (InputMethodManager) 
     getSystemService(Context.INPUT_METHOD_SERVICE); 
    mgr.showSoftInput(txtSearch, InputMethodManager.SHOW_IMPLICIT); 

回答

0

这为我工作:

@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; 

}