Dialog example in android

I want to display a dialog when a button is clicked. Here is my code, but it does not work.

AlertDialog.Builder builder = new AlertDialog.Builder(
                        getApplicationContext());
                builder.setCancelable(true);
                builder.setTitle("Title");
                builder.setInverseBackgroundForced(true);
                builder.setPositiveButton("Yes",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                dialog.dismiss();
                            }
                        });
                builder.setNegativeButton("No",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                dialog.dismiss();
                            }
                        });
                AlertDialog alert = builder.create();
                alert.show();
+3
source share
4 answers

try it,

instead of passing getApplicationContext () pass this;

AlertDialog.Builder builder = new AlertDialog.Builder(this);
+7
source

try the following:

AlertDialog.Builder builder = new AlertDialog.Builder(YourActivityName.this);
+3
source

, , , ,

https://github.com/houmanka/DialogMaker

OnClickListener, . , . Standard Neutral.

, -. .

0

AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
-1

All Articles