-1

I have couple of dialogs where the user can go back and forth. One of which is a custom dialog with an editText. I want the description editText to be always blank. I used

     description.setText("");

When I edit the description text to for instance "abcd", move back to the DIALOG_THREE and then to DIALOG_FOUR. description.setText(""); is not called. The changed text "abcd" remains on the edit text. Can experts please suggest how I can set it to blank when I move from one dialog to another.

    @Override
@Deprecated
protected Dialog onCreateDialog(int id) {
    Dialog dialog = null;

    AlertDialog.Builder builder = new AlertDialog.Builder(this,
            android.R.style.Theme_DeviceDefault_Light_DarkActionBar);

    switch (id) {       

    case DIALOG_THREE:

        builder.setCancelable(false);
        builder.setTitle("Incident Catagory");
        builder.setSingleChoiceItems(incidentCatagory, -1,
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub

                    }
                });
        builder.setPositiveButton("next",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                        showDialog(DIALOG_FOUR);


                    }

                });
        builder.setNegativeButton("Back",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                        showDialog(DIALOG_TWO);

                    }
                });

        return builder.create();

    case DIALOG_FOUR:

        LayoutInflater inflaterFour = this.getLayoutInflater();
        final View inflatorFour = inflaterFour.inflate(
                R.layout.dialog_incidents_four_description, null);

        builder.setView(inflatorFour);
        description = (EditText) inflatorFour.findViewById(R.id.etDescription);
        description.setText("");
        builder.setPositiveButton("Next", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                showDialog(DIALOG_FIVE);
                String desc = description.getText().toString();
            }
        });
        builder.setNegativeButton("Back", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                showDialog(DIALOG_THREE);

            }
        });
        return builder.create();

Thank you very much.

BRDroid
  • 3,920
  • 8
  • 65
  • 143
  • i really did not get your requirement, please can you explain little bit more. – InnocentKiller Mar 05 '14 at 16:35
  • in DIALOG_FOUR I have a description editText which i am trying to set it blank using description.setText("");. If i change the description text in DIALOG_FOUR, move to DIALOG_THREE and come back to DIALOG_FOUR, description.setText(""); is not called. I basically want the description text to be blank when i come back to DIALOG_FOUR. hope this is bit clear. thank you – BRDroid Mar 05 '14 at 16:39
  • Okay try my below code and let me know whether it is working or not. – InnocentKiller Mar 05 '14 at 16:43

2 Answers2

0

add description.setText(""); inside the Next and Back button's onClick() method to blank the edidtext. So, your DIALOG_FOUR will be as below...

case DIALOG_FOUR:

    LayoutInflater inflaterFour = this.getLayoutInflater();
    final View inflatorFour = inflaterFour.inflate(
            R.layout.dialog_incidents_four_description, null);

    builder.setView(inflatorFour);
    description = (EditText) inflatorFour.findViewById(R.id.etDescription);
    description.setText("");
    builder.setPositiveButton("Next", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            showDialog(DIALOG_FIVE);
            String desc = description.getText().toString();

            description.setText("");
        }
    });
    builder.setNegativeButton("Back", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {

            description.setText("");

            showDialog(DIALOG_THREE);

        }
    });
    return builder.create();
Hamid Shatu
  • 9,664
  • 4
  • 30
  • 41
0

add description.setText(""); inside the Next button's onClick() of your DIALOG_THREE. So basically your DIALOG_THREE will look something like this.

You just have to set description.setText(""); this code inside your DIALOG_THREE next button.

case DIALOG_THREE:

        builder.setCancelable(false);
        builder.setTitle("Incident Catagory");
        builder.setSingleChoiceItems(incidentCatagory, -1,
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub

                    }
                });
        builder.setPositiveButton("next",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                        showDialog(DIALOG_FOUR);
                        description.setText("");        //  Add this line here
                    }

                });
        builder.setNegativeButton("Back",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                        showDialog(DIALOG_TWO);

                    }
                });

        return builder.create();
InnocentKiller
  • 5,234
  • 7
  • 36
  • 84