我想调用Main Activity中的方法来使用
来调用一个新的Fragment
((FragmentActivity)Activity).ShowFragment(new SmokeSensor());
然而它会抛出错误:
无法访问外部类型的非静态成员
'Android.Support.V4.App.Fragment'通过嵌套类型
“*******。Fragments.Dashboard.ViewAdapter`
我做错了什么?
代码:
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;
}
答案 0 :(得分:0)
为什么你的“Android.Support.V4.App.Fragment”在*******中只能是静态的.Fragments.Dashboard.ViewAdapter?