i created alert dialogue but title and message are not shown here is my code for alert dialogue
holder.add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(context);
}
builder.setTitle("Alert");
builder.setMessage("Are you sure")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
});
You have to pass theme as well in AlertBuilder.
No need to call the create() method if you have called show(). Because internally the show() method calls create().
Note: I can clearly say the issue from my experience. I missed to pass theme.
DOES NOT WORK:
WORKS SUCCESFULLY:
Instead of
context
, try to useActivityName.this
.I don't know what is causing it, but for start I'm pretty sure you don't need to call
builder.create()
thendialog.show()
separately.Call directly
builder.show()
and let the Alert Dialog Builder handle its creation and display. If you really need thedialog
instance, get it from the result of thebuilder.show()
.About the lack of texts, maybe you are overriding some style, have you checked if the texts are simply White colored and because of that are "invisible"?