I'm new with android.
Currently I want to show an AlertDialog
box with 'OK' & 'Cancel' buttons.
The default is PositiveButton: Left, NegativeButton: Right
Can you let me know how can I move the PositiveButton to the right side & NegativeButton to the left side?
Is there any chance/trouble if Negativebutton cause a bad sound when pressing OK, if We change text "OK" to NegativeButton & "Cancel" to PositiveButton.
My Code:
AlertDialog.Builder builder = new AlertDialog.Builder(SUtils.getContext());
builder.setMessage("Confirmation?")
.setCancelable(false)
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//Todo
dialog.cancel();
}
})
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//TOdo
}
})
dialog = builder.create();
Thanks, Angel
This might not be a direct answer. But just some information on related topic. From this thread in Google's own forum, Romain guy said..
Going forward the order of positive/negative buttons will be the one used in ICS.
and the convention per OS version is
If it is a convention, that android/Google wants to follow, isn't it better you follow the same, since your users won't be using your app alone. After all user friendliness is the first thing a developer looks for..
AlertDialog.Builder builder = new AlertDialog.Builder(SUtils.getContext());
builder.setMessage("Confirmation?")
.setCancelable(false)
.setNegativeButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//TOdo
}
})
.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//TOdo
dialog.cancel();
}
})
diaglog = builder.create();
But I recommend to go along with the convention unless you have a good reason to change the order. That will make easier for users to use your application.
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