Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Yes/No-Dialog instead of OK/Cancel

Tags:

android

I hate the OK/Cancel dialogs, because if my application ask somebody if (s)he really want to do something you should never answer with "Cancel".

A little example:

final AlertDialog.Builder b = new AlertDialog.Builder(this);
b.setIcon(android.R.drawable.ic_dialog_alert);
b.setTitle("Hello World");
b.setMessage("Did you do your homework?");
b.setPositiveButton(android.R.string.yes, null);
b.setNegativeButton(android.R.string.no, null);
b.show();

Is it possible that the constants "yes" and "no" really means "yes" and "no" with localization? Or have I do this explicit in my string resource and can't use global constants. So I replace the two lines with:

b.setPositiveButton("Yes", null);
b.setNegativeButton("No", null);

(or the resources instead of constants here)

Sincerely xZise

like image 903
xZise Avatar asked Oct 12 '10 22:10

xZise


People also ask

Can we change OK cancel on confirm box?

confirm() method, which contains the confirmation message string, ok, and cancel button. The programmer can't change the confirm box style and button label if they use the default confirm box.

How to show Yes No alert in JavaScript?

You can create a JavaScript confirmation box that offers yes and no options by using the confirm() method. The confirm() method will display a dialog box with a custom message that you can specify as its argument.


2 Answers

Be aware that the contents of these text resources in English are actually "OK" and "Cancel", not Yes and No. So if you need Yes and No, you must use your own string resources. See for example http://code.google.com/p/android/issues/detail?id=3713 and http://groups.google.com/group/android-developers/browse_thread/thread/30b589fa9aca185a

like image 59
Asmo Soinio Avatar answered Oct 13 '22 00:10

Asmo Soinio


A quick google search reveals that there are several apps that do exactly that, including Google's own My Tracks app, so I'd say it's safe to use android.R.string.yes.

Example: http://mytracks.googlecode.com/hg/MyTracks/src/com/google/android/apps/mytracks/io/backup/ExternalFileBackup.java?r=5ebff81c1c25d9600efb5d88eecc3e068ec22ae9

like image 25
EboMike Avatar answered Oct 12 '22 23:10

EboMike