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

时间:2016-08-29 08:55:39

标签: java android android-mapview

这是我的onNavigationItemSelected方法:

        }

2 个答案:

答案 0 :(得分:1)

这样做:

 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();
            }

答案 1 :(得分:0)

public void onDestroyView() {
    super.onDestroyView();
    FragmentManager fManager = getActivity().getSupportFragmentManager();
    Fragment frag = fManager.findFragmentById(R.id.map);
    if (frag != null)
        fManager.beginTransaction().remove(frag).commit();
}

将其保留在片段中