Reputation: 3711
AlertDialog not showing send button. Below is the code. Please tell me what mistake I have made in my code.
protected Dialog onCreateDialog(int id) {
final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage("Enter Holla message");
EditText hollaMessage = new EditText(this);
dialog.setView(hollaMessage);
dialog.setCancelable(false);
dialog.setPositiveButton("Send", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
List result = new ArrayList();
}
});
dialog.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dismissDialog(0);
}
});
AlertDialog alert = dialog.create();
return alert;
}
Upvotes: 3
Views: 10562
Reputation: 7635
There is also option of adding neutralbutton. You can add neutral button, as similar to positive and negative button.
Now your next comment would be if I want to add 4 buttons then?
Then simply make the layout in XML of all the four buttons and inflate it to set it on dialog.
This will solve all your doubts.
Upvotes: 3
Reputation: 9
add ".show()" end of any button. for Exam:
dialog.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dismissDialog(0);
}
}).show();
Upvotes: 0
Reputation: 13815
You set the positive button twice.. make it setNagativeButton("Cancel"
.....
protected Dialog onCreateDialog(int id)
{
final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage("Enter Holla message");
EditText hollaMessage = new EditText(this);
dialog.setView(hollaMessage);
dialog.setCancelable(false);
dialog.setPositiveButton("Send", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
List result = new ArrayList();
}
});
dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dismissDialog(0);
}
});
AlertDialog alert = dialog.create();
return alert;
}
Upvotes: 4