Wrong Yes/No text using Android Resource String

那年仲夏 提交于 2020-05-15 02:41:04

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/15181720/wrong-yes-no-text-using-android-resource-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!