Android Customized Listviewadapterdialog隐藏了softinputkeyboard

时间:2017-10-09 05:19:54

标签: android dialog android-edittext keyboard

我面临的情景如下:

  

我的对话框edittext的焦点对准我希望键盘出现在   对话框。

enter image description here

我在SO中经历了这么多答案。但没有工作

  

适配器类edittext onfocus中的代码

 edittext.setOnFocusChangeListener(new OnFocusChangeListener() {

    public void onFocusChange (View v,boolean hasFocus){
        edittext.post(new Runnable() {

            public void run() {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
            }
        });
  

列表视图

LayoutInflater li = LayoutInflater.from(context);
            View promptsView = li.inflate(R.layout.custom_dialog, null);
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setView(promptsView);
            builder.setTitle(" Please select size");

            listView = (ListView) promptsView.findViewById(R.id.listt);
            dataAdapter = new MyCustomAdapter(context, R.layout.size_info,
                    sizePojoList, active);
            listView.setAdapter(dataAdapter);
            listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
            listView.setItemsCanFocus(true);

1 个答案:

答案 0 :(得分:0)

尝试:

dialog.getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);