1

Please, i would like to show back details after the user must have input something, back on alert dialog box in 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.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Godymn
  • 23
  • 7
  • Just calling `editText.getText().toString();` doesn't do anything. Please show some more code and format it as code. – Twometer Feb 11 '18 at 10:10

2 Answers2

0

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. Calling editText.getText().toString() does not do anything but return a String. It does not assign it to anything. An example with an AlertDialog would be the following:

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. 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.

Twometer
  • 1,561
  • 2
  • 16
  • 24
  • @Twometer...Many thanks for the help man....i have the alert dialog function all set up....the line of code i was actually looking is: builder.setMessage(editText.getText().toString()); . I also have another challenge, i cannot get the date and time too. I saw the get.Month() helper but it still doesn't work....Any help will be appreciated to show the date and time back to the user... – Godymn Feb 12 '18 at 04:00
  • @Godymn No problem. Also, if my answer helped it would be appreciated if you accept/upvote my answer ;-). – Twometer Feb 12 '18 at 07:54
  • @Godymn And, to get the current time you should take a look at this post: https://stackoverflow.com/questions/5175728/how-to-get-the-current-date-time-in-java – Twometer Feb 12 '18 at 07:55
0

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();
                        }
                    });
Godymn
  • 23
  • 7