0
votes

I have a main activity that implements the bottom navigation view with 5 fragments on it. For example, when I press the search button in the first fragment and then fragment search was displayed. But when I go to another bottom navigation view (fragment c) and pressing back on the phone, it causing overlapping between fragment A and fragment C.

This is the code between fragment A and fragment search

 FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    searchHerbs searchHerbs = new searchHerbs();
    searchHerbs.setArguments(arguments);
    ft.replace(R.id.main_frame, searchHerbs);
    ft.addToBackStack(null);
    ft.commit();

this is the code of fragment transaction between bottom navigation view fragment

FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.main_frame,fragment);
    fragmentTransaction.commit();

If I trace the code. the problem is : 1. There is no addbackstack when I leave the fragment search, I want to add it in onDestroyView but I don't know how. 2. I went to fragment search from fragment A using addbackstack(null). 3. when I press another fragment from bottom navigation view (fragment c) and press back. it causing pop fragment to fragment A.

I already tried with adding addbackstack(null) in the fragment transaction on the bottom navigation view. The problem is solved, but it makes another problem like : 1. it causing blank fragment when I press back stack before the apps close. 2. active bottom navigation doesn't change when I press back even though the fragment was changed.

overlapping fragment image

1

1 Answers

0
votes

I know a trick but its work in progress.In the new Fragment use the root layouts background as white and make it clickable like

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                     xmlns:app="http://schemas.android.com/apk/res-auto"
                     xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_margin="5dp"
                     android:padding="5dp"
                     android:background="@color/white"
                     android:clickable="true"
                     app:cardCornerRadius="10dp"
                     app:contentPadding="5dp">