设置光标聚焦输入框(EditText)并弹出软键盘(在适配器中设置)

参考代码:

public void setFocusEditTextAndShowSoftInput(final EditText editText){
        editText.setFocusable(true);
        editText.setFocusableInTouchMode(true);
        editText.requestFocus();//聚焦
        //判断当前editText是否绘制完成,绘制完成后再进行展示软键盘
        editText.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                InputMethodManager inputManager = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.showSoftInput(editText, 0);//展示软键盘
            }
        });
    }
原文地址:https://www.cnblogs.com/Gavin-Xp/p/10272075.html