duplicated id with fragment

后端 未结 3 968
情歌与酒
情歌与酒 2020-12-01 07:00

I\'m trying to applicate drawernavigation (my first fragment is a map & the others are just some fragments with simple layouts).So it runs fine & I can navigate betw

3条回答
  •  温柔的废话
    2020-12-01 07:31

    I think you have to try to retrieve old Fragments instance instead of recreating it each time a drawer item is selected. In your displayView method of LoginScreen Activity, you have to do something like that in the switch:

    Fragment fragment = null;
    String title = getResources().getString(SOME_FRAGMENT_TITLE);
    switch (position) {
    case 1:
       fragment = (YourFragment) fm.findFragmentByTag(title);
       if (fragment == null) fragment = new YourFragment();
       break;
     }
    

提交回复
热议问题