0

I cannot figure out why the "Close" button is showing 1st on the left and the "Help Translate" button on the right.

enter image description here

I want the "Help Translate" button on the left and "Close" on the right

case R.id.action_translate:
            builder = new AlertDialog.Builder(this);
            builder.setIcon(R.drawable.ic_launcher);
            builder.setTitle(getResources().getString(R.string.app_name));
            builder.setMessage(getResources().getString(R.string.translate_text));
            builder.setPositiveButton ("Help Translate", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
                            startActivity(browserIntent);
                        }
                    });
            builder.setNegativeButton("Close", null);
            builder.setCancelable(true);
            alert = builder.create();
            alert.show();
            return true;
Jacques Krause
  • 5,523
  • 9
  • 27
  • 43
  • just some information on related [topic](http://stackoverflow.com/questions/13644448/android-alertdialog-move-positivebutton-to-the-right-and-negativebutton-on-the-l) – JK Park May 04 '15 at 08:03

2 Answers2

1

I want the "Help Translate" button on the left and Close on the right

you shouldn't really do it. The order is decided by the operating system in this case. In the up to gingerbread, the order was positive-neutral-negative, starting from honeycomb the order is negative-neutral-positive. Even though you couldn't like it, it is consistent with the way the operating system works, and in the aim to give the user the same UX across the applications, you shouldn't change it

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
0
case R.id.action_translate:
        builder = new AlertDialog.Builder(this);
        builder.setIcon(R.drawable.ic_launcher);
        builder.setTitle(getResources().getString(R.string.app_name));
        builder.setMessage(getResources().getString(R.string.translate_text));
        builder.setNegativeButton("Help Translate", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
                        startActivity(browserIntent);
                    }
                });
        builder.setPositiveButton ("Close", null);
        builder.setCancelable(true);
        alert = builder.create();
        alert.show();
        return true;

Actually its the android standard!! if you dont want to follow it then you can use this trick :)

Preethi Rao
  • 5,117
  • 1
  • 16
  • 29