What Should i Write in the Runnable Run Method to cancel the Alert.Bulider??
AlertDialog.Builder ad;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Context context=this;
ad = new AlertDialog.Builder(context);
ad.setTitle("Warning");
ad.setMessage("Just Testing It");
ad.setPositiveButton("Yes", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
ad.setNegativeButton("Nooooo", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
ad.show();
Handler h=new Handler();
h.postAtTime(r, 10000);
}
public Runnable r=new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
}
};
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.
setCancelable(false); AlertDialog dialog = builder. show(); In order to dismiss the dialog, you can call dismiss function like this.
Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons.
You cannot hide a AlertDialog.Builder
. Instead declare the member variable ad
as AlertDialog
, create the AlertDialog using the builder and assign it to ad by writing ad = builder.create()
. In the run method call ad.cancel()
;
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