18

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

3 Answers 3

27

WARNING: yes in android.R.string has been deprecated.

Maybe was deprecated because it's confusing 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

1
  • 2
    if I have dialog with a message something like Do you want to download it? Then yes / no is better. I don't understand why internal string resources android.R.string.no and android.R.string.cancel both contains word Cancel (doesn't make any sense)
    – user924
    Dec 7, 2017 at 22:14
3

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

5
  • Hmmm okay, but where does your example use android.R.string.yes ? And I don't want to know if it is "save", I only want to know how to rename the buttons to Yes/No using constants named like this. Or if I had to add the values manually. I'm not a native english speaker, but is it common to use Ok/Cancel-Dialogs instead of Yes/No-Dialogs? For me it's sounds ugly to answer "Did you done your homework?" with "OK" or "Cancel". Sincerely xZise
    – xZise
    Oct 12, 2010 at 22:44
  • For me, "did you done your homework" sounds ugly :) It's "Did you do your homework". Just search for "android.R.string.yes" in the link I posted. Actually, it changed, check this link here: mytracks.googlecode.com/hg/MyTracks/src/com/google/android/apps/…
    – EboMike
    Oct 12, 2010 at 22:52
  • And to answer your question - you're absolutely right, "Yes" and "No" would be much more appropriate button names, and you'd do the right thing to change them. Windows even has MB_YESNO as an option for its dialogs. Android doesn't, but your code would do the proper thing.
    – EboMike
    Oct 12, 2010 at 22:54
  • Hmmm okay thanks, I hoped I only miss some constant. Sincerely xZise
    – xZise
    Oct 13, 2010 at 7:51
  • @EboMike Please update the link as it's not available. Jan 23, 2020 at 11:01
3

What you have provided should work. (An aside, in proper English your question should say "Have you done your homework? Or Did you do your homework?)

I don't think there is any global english standard regarding ok/cancel and yes/no. It really depends on the context. There are certain contexts where one or the other would make more sense. I things it's perfectly OK to use yes/no if that makes more sense for the kinds of things you are asking.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.