EditText request focus not working

后端 未结 11 644
自闭症患者
自闭症患者 2020-12-15 17:03

I have an EditText and a Button. On click of the button i want to open the EditText keyboard and at the same time request focus on the

11条回答
  •  温柔的废话
    2020-12-15 17:12

    As an extension to this answer (I didn't add it as a comment because of reputation...).

    If you want to reduce the delayed time to zero, use handler.post() instead. Full code:

    final Handler handler = new Handler();
    handler.post(new Runnable() {
        @Override
        public void run() {
            lastview.getEditText().clearFocus();
            m_SearchEditText.requestFocus();
            InputMethodManager mgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    
    
            mgr.showSoftInput(mLastNameET, InputMethodManager.SHOW_IMPLICIT);
        }
    });
    

提交回复
热议问题