hi friends i set a dialog box with yes and no button but only NO is visible YES button is not visible please suggest me
This is the code i used thanks in advance
alertDialog.setButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
// Write your code here to invoke YES event
Toast.makeText(getApplicationContext(), "You clicked on YES", Toast.LENGTH_SHORT).show();
}
});
// Setting Negative "NO" Button
alertDialog.setButton("NO bad", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to invoke NO event
Toast.makeText(getApplicationContext(), "You clicked on NO", Toast.LENGTH_SHORT).show();
dialog.cancel();
}
});
I think you should follow this Builder pattern example given below.
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setCancelable(true)
.setTitle(titleResourceId)
.setMessage(messageResourceId)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeToast(mContext, "Yes", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeToast(mContext, "No", Toast.LENGTH_SHORT).show();
}
});
builder.show();
Using setPositiveButton()
and setNegativeButton()
allows android to place the buttons in the correct order according to the platform the app runs in.
instead of
alertDialog.setButton
use
alertDialog.setPositiveButton
alertDialog.setNegativeButton
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With