Identify which AlertDialog triggered onClick(DialogInterface dialog, int which)

Posted by Kurian on Stack Overflow See other posts from Stack Overflow or by Kurian
Published on 2010-02-22T06:05:45Z Indexed on 2010/04/02 7:03 UTC
Read the original article Hit count: 512

Filed under:
|
|
|
|

I'm creating a dialog as follows:

 @Override
 protected Dialog onCreateDialog(int id) {
  switch (id) {
  case DIALOG_1:
   return new AlertDialog.Builder(this)
   .setTitle(R.string.s_dlg1)
   .setPositiveButton(android.R.string.ok, this)
   .create();

  case DIALOG_2:
   ...
   ...
  }

  return null;
 }

 @Override
 public void onClick(DialogInterface dialog, int whichButton) {
  if (dialog == ???) {
   ...
  }
  else if (dialog == ???){
   ...
  }
 }

How do I identify which dialog triggered the onClick method? I can't declare the interface methods as in-line when creating the dialog because I want to access variables in my class. Every other interface passes some sort of id to its methods to identify which object called the method, but I can't seem to do anything with 'DialogInterface dialog'.

© Stack Overflow or respective owner

Related posts about android

Related posts about onclick