EditText request focus not working

后端 未结 11 669
自闭症患者
自闭症患者 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:19

    In my case it worked by adding a handler after you clicked to button and focus set in another view the focus can get back to your needed view.

    just put this in your code:

    final Handler handler = new Handler();
                    handler.postDelayed(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);
    
                        }
                    }, 100);
    

    I hope it was helpful

提交回复
热议问题