Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong Yes/No text using Android Resource String

I am building a dialog in Mono for Android like this:

AlertDialog.Builder builder = new AlertDialog.Builder(Context);
builder.SetTitle(Context.GetString(Resource.String.MyTitle));
builder.SetMessage(Context.GetString(Resource.String.MyQuestion);
//YES, not OK
builder.SetPositiveButton(Android.Resource.String.Yes, new EventHandler<DialogClickEventArgs>((dlgSender, dlgEvt) => { doSomething();});
builder.SetNegativeButton(Context.GetString(Android.Resource.String.No), new EventHandler<DialogClickEventArgs>((dlgSender, dlgEvt) => {    doSomethingElse();}));
builder.SetNeutralButton(Context.GetString(Android.Resource.String.Cancel), 
                                         new EventHandler<DialogClickEventArgs>((dlgSender, dlgEvt) => {}));

Dialog dialog = builder.Create();
dialog.Show();

This brings up my question with three buttons: "Cancel, Cancel, Ok" whereas I expected to get "No, Cancel, Yes". Is anything wrong with my code above or is there something wrong with Mono for Android here?

like image 801
Philipp Avatar asked Mar 03 '13 02:03

Philipp


1 Answers

android.R.string.yes and android.R.string.no (used as Android.Resource.String.* in Monodroid) are just resource names, which equate to "OK" and "Cancel". You'll have to make your own string resources.

From Android's strings.xml (Android 4.2):

<!-- Preference framework strings. -->
<string name="ok">OK</string>
<!-- Preference framework strings. -->
<string name="cancel">Cancel</string>
<!-- Preference framework strings. -->
<string name="yes">OK</string>
<!-- Preference framework strings. -->
<string name="no">Cancel</string>
like image 84
Cat Avatar answered Oct 15 '22 19:10

Cat