Bouss
Bouss

Reputation: 205

Pop up dialog is shown twice in android

I'm using a alertdialog to show a message to the user, but when the ok button is pressed, the dialog is shown again. After pressing the ok button for the second time, that's when the dialog finally disappears.

Here is my code:

if(Integer.parseInt(hours) < 0 || Integer.parseInt(minutes) < 0)
        {
            new AlertDialog.Builder(this)
            .setTitle("Warning")
            .setMessage("The ending time cannot be earlier than the start time!")
            .setCancelable(true)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) { 
                    // continue with delete
                    dialog.cancel();
                }
             })
            .setIcon(android.R.drawable.ic_dialog_alert)
             .show();

        }

EDIT: The code is triggered when a user fills a ending time (in an EditText) that is earlier than the start time, using time pickers. The if clause is called in the unlock event of the EditText for the ending time/

Anybody got an idea why this is happening?

Upvotes: 1

Views: 3861

Answers (1)

Don Chakkappan
Don Chakkappan

Reputation: 7560

Actually you are triggering twice the code block to show the Alert Dialogue.

So Alert Dialogue is showing one above another.

It is not related with OK button click.

There is no issues with the code snippet provided.

Upvotes: 1

Related Questions