简体   繁体   English

如何在警报对话框上显示用户输入的详细信息?

[英]How to show user input details back on alert dialog?

Please, i would like to show back details after the user must have input something, back on alert dialog box in Android studio. 请在用户必须输入某些内容后,在Android Studio的警报对话框中显示详细信息。 I used this code below: 我在下面使用了这段代码:

editText = (EditText) findViewById(R.id.my_edit_txt);
editText.getText().toString(); 

But it doesn't show on the confirmation dialog box I created. 但它不会显示在我创建的确认对话框中。

It looks like you didn't set the text of your AlertDialog, but this is just an assumption because there is not enough code in your question. 似乎您没有设置AlertDialog的文本,但这只是一个假设,因为您的问题中没有足够的代码。 Calling editText.getText().toString() does not do anything but return a String. 调用editText.getText().toString()不会执行任何操作,但会返回一个String。 It does not assign it to anything. 它不会将其分配给任何东西。 An example with an AlertDialog would be the following: 下面是一个带有AlertDialog的示例:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(editText.getText().toString());
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
               // User clicked OK button
           }
       });
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
               // User cancelled the dialog
           }
       });
// Set other dialog properties
...

// Create the AlertDialog
AlertDialog dialog = builder.create();

I've took this example from Android Developers and modified it so that it includes the text of your EditText. 我已经从Android开发人员那里得到了这个示例,并对其进行了修改,以使其包含您EditText的文本。 This code should work because you not only call the toString() method but also assign it's return value to the AlertDialog's message property. 这段代码应该起作用,因为您不仅要调用toString()方法,而且还要将其返回值分配给AlertDialog的message属性。

This is my entire code for the alert dialog box: 这是警报对话框的全部代码:

public void alertdialog(View view){ 公共无效警报对话框(视图){

           mybtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    AlertDialog.Builder cfmalt = new AlertDialog.Builder(Dashboard.this);
                    //cfmalt.setMessage("Do you want to quit?").setCancelable(false);
                   //editText.getText().toString();
                    cfmalt.setMessage(editText.getText().toString()+"\n"+ vol_edit2.getText().toString());
                    cfmalt.setMessage(dt.getMonth())
                    //cfmalt.setMessage("Name:").setMessage(vol_edit2.getText().toString());


                    cfmalt.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            finish();
                        }
                    });
                    cfmalt.setNegativeButton("No", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            dialogInterface.cancel();
                        }
                    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM