android – 用户可以选择输入详细信息或取消的对话框或表单

在我的应用程序中,我希望用户可以看到一个对话框或表单,允许用户输入他们的姓名和电话号码.

我看不到任何可供用户在弹出窗体或对话框中输入详细信息的内容.有没有简单的方法来做到这一点.

谢谢

解决方法

您还可以使用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",int which) {
            dialog.dismiss();
        }
    });
    AlertDialog dialog = builder.create();

相关文章

Android 如何解决dialog弹出时无法捕捉Activity的back事件 在...
Android实现自定义带文字和图片的Button 在Android开发中经常...
Android 关于长按back键退出应用程序的实现最近在做一个Andr...
android自带的时间选择器只能精确到分,但是对于某些应用要求...