i have activity called "A" which displays the list of items.On clicking update button it shows the custom dialog (activity is showed in the back)with the list of items selected.When Order button inside custom dialog is clicked .
Kindly help me to solve this problem.
noData.setPositiveButton("Ok", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
How can i add the finish() after cancelling the alertDialog()
AlertDialog generally consists of the main title, the message, and two buttons, technically termed as a positive button and a negative button. Both positive and negative buttons can be programmed to perform various actions. By default, the negative button lets close the AlertDialog without any additional lines of code.
setPositiveButton() is used to create a positive button in alert dialog and setNegativeButton() is used to invoke negative button to alert dialog. Here setNeutralButton() is used to create a neutral cancel button.
If you wish to prevent a dialog box from closing when one of these buttons is pressed you must replace the common button handler for the actual view of the button. Because it is assigned in OnCreate(), you must replace it after the default OnCreate() implementation is called.
You can use the methods cancel() or dismiss() .
You'll need something like this:
noData.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Finish activity
finish();
}
});
Just adding finish() inside the onClick should do the trick.
See the code below (replace MyActivity
with the name of your activity that this code is living in):
noData.setPositiveButton("Ok", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
MyActivity.this.finish();
}
});
Adding this
is very important!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With