[英]Cannot access a non-static member of outer type X via nested type X
I want to call a method in the Main Activity to call a new Fragment using 我想调用Main Activity中的方法来调用一个新的Fragment
((FragmentActivity)Activity).ShowFragment(new SmokeSensor()); ((FragmentActivity)Activity).ShowFragment(new SmokeSensor());
however it throws the error: 但它会抛出错误:
Cannot access a non-static member of outer type
无法访问外部类型的非静态成员
'Android.Support.V4.App.Fragment' via nested type
'Android.Support.V4.App.Fragment'通过嵌套类型
'*******.Fragments.Dashboard.ViewAdapter`
“*******。Fragments.Dashboard.ViewAdapter`
What am I doing wrong? 我究竟做错了什么?
Code: 码:
public void ShowFragment(SupportFragment fragment) {
var transaction = SupportFragmentManager.BeginTransaction();
connectionStatus.Visibility = ViewStates.Gone;
if (!ConnectionDetector.IsConnected(this)) {
connectionStatus.Visibility = ViewStates.Visible;
transaction.Detach(currentFragment);
transaction.Commit();
drawerLayout.CloseDrawer(leftDrawer);
return;
}
if (fragment == currentFragment) {
transaction.Detach(currentFragment);
transaction.Attach(currentFragment);
transaction.Commit();
drawerLayout.CloseDrawer(leftDrawer);
return;
}
transaction.SetCustomAnimations(Resource.Animation.slide_in,
Resource.Animation.slide_out);
transaction.Replace(Resource.Id.fragment_container, fragment);
transaction.Commit();
drawerLayout.CloseDrawer(leftDrawer);
currentFragment = fragment;
}
why you'r "Android.Support.V4.App.Fragment" can be only static in *******.Fragments.Dashboard.ViewAdapter ? 为什么你的“Android.Support.V4.App.Fragment”在*******中只能是静态的.Fragments.Dashboard.ViewAdapter?
see that cannot-access-a-non-static-member-of-outer-type or this 看到无法访问非静态成员的外部类型或此 类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.