我正在使用MonoDevelop for Android,我想要实现一个消息框。
我目前正在MapsAndLocationDemo中尝试此代码。
这是我的代码:
public void createMessageBox (string stringQuestion)
{
var builder = new AlertDialog.Builder(this);
builder.SetTitle ("Test");
builder.SetIcon (Resource.Drawable.Icon);
builder.SetMessage (stringQuestion);
builder.SetPositiveButton ("Yes", (sender, e) => {
Toast.MakeText (this, "You clicked positive button", ToastLength.Short).Show ();
});
builder.SetNegativeButton ("No", (sender, e) => {
Toast.MakeText (this, "You clicked negative button", ToastLength.Short).Show ();
});
builder.SetNeutralButton ("Maybe", (sender, e) => {
Toast.MakeText(this, "You clicked neutral button", ToastLength.Short).Show ();
});
var dialog = builder.Create ();
dialog.Show ();
}
当从主“OnCreate”函数调用时,此代码工作正常。但是,我想从基于'ItemizedOverlay'的'Overlay'调用此代码。
我收到以下错误:
无法通过嵌套类型“MapsAndLocationDemo.MapWithOverlayActivity.MapItemizedOverlay”
访问外部类型“MapsAndLocationDemo.MapWithOverlayActivity”的非静态成员
我怎么能让这个工作?或者有更好的方式来显示消息框吗?
由于
答案 0 :(得分:1)
所有需要做的就是使函数变为静态。