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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With