简体   繁体   中英

Fragment navigation issue

I have a fragment which contains a list.Upon selecting one element from the list it navigate to another fragment with some specific data. When I back pressed from fragment 2, I get fragment 1 where the list is showing twice.

fragment1 before back pressed

受压前

Fragment1 after back pressed

背压后

Below is my fragment transaction code from Fragment1 to Fragment2

    fragmentManager = mainActivityContext.getSupportFragmentManager();
    fragmentTransaction = fragmentManager.beginTransaction();
    SurveyOverView surveyOverView = new SurveyOverView();
    Bundle bundle = new Bundle();
    bundle.putParcelable("SURVEY_QUESTION",surveys.get(position));
    surveyOverView.setArguments(bundle);      fragmentTransaction.replace(R.id.fragment_container,surveyOverView,FRAG_TAG);
    fragmentTransaction.addToBackStack(null);

    fragmentTransaction.commit();

Please help I do not know how to resolve this.

The most possible reason of this issue is you've added data to existing list without clearing its current data first. Post your code for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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