Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlertDialog not showing positive and negative button in Samsung Galaxy s4

I have displayed AlertDialog with 2 buttons i.e. Yes and Cancel, here is the code.

final AlertDialog.Builder builder = new AlertDialog.Builder(RiderDetailActivity.this);
builder.setCancelable(false);
builder.setMessage("Are you sure?");

final AlertDialog dialog = builder.create();
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
        dialog.dismiss();
    }
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
        dialog.dismiss();
    }
});
dialog.show();

This doesn't show yes and cancel button only on samsung galaxy s4

enter image description here

But when i use it with with dialog.setButton it works perfectly

dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
        dialog.dismiss();
    }
});
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
        dialog.dismiss();
    }
});

enter image description here

Note : builder.setPositiveButton and builder.setNegativeButton is creating problem on just Samsung Galaxy S4, for other devices it is working perfectly.

UPDATE

I need to create dialog after setting buttons to builder, but my concern is why it was working with other devices and just creating problem with Samsung Galaxy S4?

like image 729
Ravi Avatar asked Dec 11 '22 13:12

Ravi


1 Answers

Try this way. I hope this will work for you.

 final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setCancelable(false);
    builder.setMessage("Are you sure?");
    builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    });
    final AlertDialog dialog = builder.create();
    dialog.show();
like image 166
SANJAY GUPTA Avatar answered Jan 16 '23 09:01

SANJAY GUPTA