0

Please tell me I think problem in return.
I have a button and I would like to open a dialog when pressed.

This is my code:

 private void settinglistners() {
    shwdlg.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            builder.setMessage("Are you sure")
                    .setTitle("Delete")
                    .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                        }
                    })
                    .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                        }
                    });
            return builder.create();

        }
    });
}
George Kagan
  • 5,913
  • 8
  • 46
  • 50
Waseem
  • 1
  • 2

1 Answers1

0

use ".show()" after creating Dialog like this

private void settinglistners() {
shwdlg.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setMessage("Are you sure")
                .setTitle("Delete")
                .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {

                    }
                })
                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {

                    }
                });
        return builder.create().show();

    }
});

}

i think this will helpful to you

Devil10
  • 1,853
  • 1
  • 18
  • 22