繁体   English   中英

使用地图视图两次按导航项时,我的应用程序崩溃

[英]My app crashes when I press navigation item twice using map View

这是我的onNavigationItemSelected方法:

        }

像这样做:

 int id = item.getItemId();
FragmentTransaction fragmentTransaction;

    if (id == R.id.nav_sports) {

        fragment = new FragmentOne();


    } else if (id == R.id.nav_food) {
        fragment = new FragmentTwo();



    } else if (id == R.id.nav_security) {
        fragment = new FragmentThree();
     }
if (fragment != null) {
                fragmentTransaction = getSupportFragmentManager().beginTransaction();
                fragmentTransaction.replace(R.id.containerView, fragment).commit();
            }
public void onDestroyView() {
    super.onDestroyView();
    FragmentManager fManager = getActivity().getSupportFragmentManager();
    Fragment frag = fManager.findFragmentById(R.id.map);
    if (frag != null)
        fManager.beginTransaction().remove(frag).commit();
}

将此保留在您的片段中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM