domshyra
domshyra

Reputation: 962

Get information from the AlertDialog

How would I make like a switch or if then statement with the varible in my code? Change the id, or something because both the id vars and the DialogInterface are the same. WOuld I use the "builder" as the code to do this?? The postive button would be a snooze button so I would prob want and If postive clicked the pull up a sleep function or create a function to make the alarm go off in however longer the users sets for snooze.

Here is my code,

AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Time to get up! How was your nap?")
            .setCancelable(false)
            .setPositiveButton("More Sleep!!",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            vibarate.cancel();
                            onPause();


                        }
                    })
            .setNegativeButton("Great! ",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            AlertDialogTest.this.finish();
                        }
                    });
    AlertDialog alert = builder.create();
    alert.show();

Upvotes: 0

Views: 317

Answers (1)

Noah
Noah

Reputation: 1966

The snooze button is an onClickListener, so really it ought to set up another alarm for a given time rather than sleeping the thread.

I've inserted a fake method: setUpNewAlarmForTime(5,TimeUnit.Seconds); In reality you are already constructing an alarm and the snooze callback just needs to use that.

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Time to get up! How was your nap?")
        .setCancelable(false)
        .setPositiveButton("More Sleep!!",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        vib.cancel();
                        onPause();

                        vib = setUpNewAlarmForTime(5,TimeUnit.Seconds);


                    }
                })
        .setNegativeButton("Great! ",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        AlertDialogTest.this.finish();
                    }
                });
AlertDialog alert = builder.create();
alert.show();

Upvotes: 1

Related Questions