Keyboard not shown when i click on edittextview in android?

后端 未结 8 2458
灰色年华
灰色年华 2020-11-27 23:03

When i click on the edittextview then some times keyboard shown or some times keyboard are not shown.

In android 2.1 it show the keyboard when i click on the edittex

8条回答
  •  感动是毒
    2020-11-27 23:30

    here's a possible solution:

    editText.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(final View v, final boolean hasFocus) {
            if (hasFocus && editText.isEnabled() && editText.isFocusable()) {
                editText.post(new Runnable() {
                    @Override
                    public void run() {
                        final InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(editText,InputMethodManager.SHOW_IMPLICIT);
                    }
                });
            }
        }
    });
    

    code is based on the next link:

    http://turbomanage.wordpress.com/2012/05/02/show-soft-keyboard-automatically-when-edittext-receives-focus/

提交回复
热议问题