Set a listener to be invoked when the neutral button of the dialog is pressed.
Parameters:
text - The text to display in the neutral button
listener - The DialogInterface.OnClickListener to use.
Returns: This Builder object to allow for chaining of calls to set methods
1. Create an AlertDialog with Supplied Arguments
2. Add the line below to the imports section.
import android.content.DialogInterface;
@Override
public void onClick(DialogInterface dialog, int which) {
// To test, Add a Toast, with a context of getBaseContext() and message such as
// "No opinion huh...."
}
});
5. The button order is defined by the OS itself. An OS change in button display order was made from API Level 10 to API Level 11.
In API Level 11+ the buttons will display in the order NEGATIVE|NEUTRAL|POSITIVE
In API Level 10 and below, the buttons will display int he order: POSITIVE|NEUTRAL|POSITIVE
API Level 10 Button order |
Next Recommended Article: How to Add an Icon/Drawable to an AlertDialog.Builder
Resources:
http://developer.android.com/reference/android/app/AlertDialog.Builder.html#setNeutralButton(java.lang.CharSequence, android.content.DialogInterface.OnClickListener)http://developer.android.com/reference/android/content/DialogInterface.OnClickListener.html
https://code.google.com/p/android/issues/detail?id=24138
http://stackoverflow.com/questions/20117732/dialog-box-positive-negative-buttons-in-different-position-depending-on-androi