Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Cancel a AlertDialog.Builder

Tags:

android

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

        }
    };
like image 697
Harinder Avatar asked Apr 05 '11 04:04

Harinder


People also ask

How do I turn off 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.

How do I dismiss Materialalertdialogbuilder?

setCancelable(false); AlertDialog dialog = builder. show(); In order to dismiss the dialog, you can call dismiss function like this.

What is AlertDialog builder in Android?

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.


1 Answers

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();

like image 133
pankajagarwal Avatar answered Sep 27 '22 21:09

pankajagarwal