【问题标题】:Dialog box or form where user can choose to enter details or cancel用户可以选择输入详细信息或取消的对话框或表单
【发布时间】:2011-03-08 16:22:19
【问题描述】:

在我的应用程序中,我希望向用户显示一个对话框或表单,允许用户输入他们的姓名和电话号码。

我看不到任何可供用户在弹出表单或对话框中输入详细信息的内容。有什么简单的方法可以做到这一点。

谢谢

【问题讨论】:

    标签: android dialog


    【解决方案1】:

    您还可以使用 AlertDialog.Builder 将布局粘贴到警报对话框中,如下所示:

        //Preparing views
        LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.dialog_layout, (ViewGroup) findViewById(R.id.layout_root));
    //layout_root should be the name of the "top-level" layout node in the dialog_layout.xml file.
        final EditText nameBox = (EditText) layout.findViewById(R.id.name_box);
        final EditText phoneBox = (EditText) layout.findViewById(R.id.phone_box);
    
        //Building dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setView(layout);
        builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                //save info where you want it
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        AlertDialog dialog = builder.create();
    

    【讨论】:

    【解决方案2】:

    您可以使用任何您想要的布局创建Custom Dialog

    【讨论】:

      猜你喜欢
      • 2011-01-28
      • 1970-01-01
      • 1970-01-01
      • 2021-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-24
      • 2013-03-12
      相关资源
      最近更新 更多