Why I want to do this is another discussion entirely, but I need to figure out the best way to make all my alert dialogs have the positive button on the right side. Note that i
Sometimes completely different perspectives are the solution to a problem, the HI-user culture.
In Android the HI is quite different because of the existence of the OS "Back" button (onBackPressed() that could also be overridden, ESC on attached physical keyboards) in the operative system HI.
this is my solution. It is work for me.
// Show alertDialog after building
AlertDialog alertDialog = createAlertDialog(context);
alertDialog.show();
// and find positiveButton and negativeButton
Button positiveButton = (Button) alertDialog.findViewById(android.R.id.button1);
Button negativeButton = (Button) alertDialog.findViewById(android.R.id.button2);
// then get their parent ViewGroup
ViewGroup buttonPanelContainer = (ViewGroup) positiveButton.getParent();
int positiveButtonIndex = buttonPanelContainer.indexOfChild(positiveButton);
int negativeButtonIndex = buttonPanelContainer.indexOfChild(negativeButton);
if (positiveButtonIndex < negativeButtonIndex) {
// prepare exchange their index in ViewGroup
buttonPanelContainer.removeView(positiveButton);
buttonPanelContainer.removeView(negativeButton);
buttonPanelContainer.addView(negativeButton, positiveButtonIndex);
buttonPanelContainer.addView(positiveButton, negativeButtonIndex);
}