Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start a new activity class in AlertDialog popup by choosing ok button

Tags:

android

button

There is first activity where users save their detail. after clicking save button an Alertdialog asking about ok or cancel . if user clicks on ok then a new activity get started.

    protected final Dialog onCreateDialog(final int id) {
    Dialog dialog = null;
    switch(id) {
    case DIALOG_ID:
        AlertDialog.Builder builder = new AlertDialog.Builder(AppointInformation.this);
        builder.setMessage("Information saved successfully ! Add Another Info?")
        .setCancelable(false)
        .setPositiveButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {

startActivity(new Intent(((Dialog)dialog).getContext(),CheckPatient.class));    
          }
        })
        .setNegativeButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        AlertDialog alert = builder.create(); 
        dialog = alert;
        break;

    default:

    }
    return dialog;
  }
like image 652
SAURABH_12 Avatar asked Apr 02 '12 10:04

SAURABH_12


1 Answers

I know it's too late but I want to answer this for helping other people, this works for me :

Intent intent = new Intent(getContext(),OtherActivity.class);
                 context.startActivity(intent);

context is the context of the current activiy.

like image 76
Valentina_Siii Avatar answered Sep 30 '22 10:09

Valentina_Siii