The simplest part is actually described in the Developer's Guide for Android, in the Dialogs tutorial.
It's pretty simple: you have to implement an interface on the Activity's side (implements NoticeDialogFragment.NoticeDialogListener
) and override the callback methods
@Override
public void onDialogPositiveClick(DialogFragment dialog) {
// User touched the dialog's positive button
...
}
@Override
public void onDialogNegativeClick(DialogFragment dialog) {
// User touched the dialog's negative button
...
}
The example I'm giving uses the DialogFragment
which doesn't exactly fit your code. However, the implementation isn't that different for you, you just have to look up the corresponding interfaces (the OnDismissListener
for instance)
You currently have this:
boolean status=false;
status=Alerts.showAlertDialog(this);
if(status){
//do this
}
else{
//do that
}
You'll have to eliminate the whole if
. Change your Activity so it implements the DialogInterface.OnClickListener
interface
public class Blah extends Activity implements DialogInterface.OnClickListener
and add the method
public void onClick(DialogInterface dialog, int which){
if (which==DialogInterface.BUTTON_POSITIVE){
//TODO: do your stuff
}
}
finally, in your Alerts.showDialog()
method change
alert.setPositiveButton(R.string.yes,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
...
}
}
);
to
alert.setPositiveButton(R.string.yes,c);
If you do have an EditText, I'd have to assume you used the technique described in the AlertDialog
documentation Class Overview. If so, since you're receiving the dialog as a parameter, you would have to find the view in the Dialog with findViewById
and extract the value that way.