【问题标题】:android open keyboard from dialog button clickandroid从对话框按钮单击打开键盘
【发布时间】:2012-07-26 11:28:42
【问题描述】:

我有一个打开对话框的表单(包括列表视图和一个按钮),如果单击按钮,对话框应该消失并且键盘应该显示在表单上

我做不到。有什么想法吗?

感谢您的帮助!

我的代码是:

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();

【问题讨论】:

    标签: android dialog keyboard


    【解决方案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

    【讨论】:

    • 不!我还有一个包含按钮和列表视图的对话框。但是问题是当我单击按钮对话框关闭但键盘没有显示时。我的问题是键盘没有显示!
    • 试试这个this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    • 2015-09-13
    • 2011-06-18
    • 2018-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多