从对话框按钮单击android打开键盘

时间:2012-07-26 11:28:43

标签: android dialog keyboard

我有一个打开对话框的窗体(包括listview和一个按钮),如果单击按钮,对话框应该消失,键盘应该显示在窗体上

我无法做到。任何想法?

感谢您的帮助!

我的代码是:

final Dialog dialog = new Dialog(context);
                 dialog.setContentView(R.layout.dialog_list_layout);
                 dialog.setCancelable(true);

                 final ListView listviewDialog = (ListView) dialog.findViewById(R.id.listViewDialog);
                 DialogListAdapter adapter = new DialogListAdapter(context, R.id.textViewItem, List);
                 listviewDialog.setAdapter(adapter);

        ((Button) dialog.findViewById(R.id.button)).setOnClickListener(new View.OnClickListener() {

                            public void onClick(View v) {                   
                                editText.setText("");


                                dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                                ((EditText) findViewById(R.id.editText)).requestFocus();
                                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                                imm.showSoftInput(((EditText) findViewById(R.id.editTextAddress)), InputMethodManager.SHOW_IMPLICIT);

                                dialog.dismiss();       
                            }
                        });
                         dialog.show();

1 个答案:

答案 0 :(得分:1)

只需创建一个对话框,然后单击其按钮编写inputmanager

的代码
 AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage(str1);
            builder.setCancelable(false);
            builder.setTitle("Status");
            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) 
                 {

                    dialog.dismiss();
                   InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                   imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);

                }
            });
            AlertDialog alert = builder.create();
            alert.show();

查看我更新的答案

<强>更新

除了我的回答,请参阅此is it possible to create listview inside dialog?ListView in AlertDialog