In my app, I show the push notification as a Dialog that has two buttons named Yes and No. I need to show a timer (20 seconds) running in the dialog's title.
If the user clicks Yes, it should go to an activity.
If the user clicks No, the dialog gets canceled before timer ends.
When the countdown finishes,the Dialog should disappear. How should I implement this?
Here is my Alert dialog Method
public void showAlertDialog(final Context context, String title, String message,
Boolean status) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
// Setting Dialog Title
alertDialog.setTitle(title);
// Setting Dialog Message
alertDialog.setMessage(message);
// Setting Icon to Dialog
//alertDialog.setIcon(R.drawable.fail);
// Setting Positive "Yes" Button
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "You clicked on YES", Toast.LENGTH_SHORT).show();
}
});
// Setting Negative "NO" Button
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "You clicked on NO", Toast.LENGTH_SHORT).show();
dialog.cancel();
}
});
// Showing Alert Message
//alertDialog.setIcon(R.drawable.counter);
alertDialog.show();
}