Fragment is updating but also having its previous view in stack

Viewed 24

I am using a fragment inside an activity. I am using the interfrace from the activity to handle the visibility of a view (specifically a linear progress indicator). I am able to handle it. The fragment view is updated but the previous state of the fragment is still visible in the background.

Below is the code which is setting the interface in the parent activity

private void addCallbacks(){
        Class<? extends FragmentActivity> activity = requireActivity().getClass();

        if(activity == HomeActivity.class){
            ((PARENT_ACTIVITY)requireActivity()).setProcessCallbackFrgDashboard(new AppCallback() {
                @Override
                public void update(boolean status) {
                    updateLoadingStatus(status);
                }
            });
        }
    }

And calling addCallback in onViewCreated method of the fragment.

I have set the onClickListener on the red rectangle to set its visibility to gone when clicked.

issue view 1

But after clicking on it ... the rectangle is removed but the previous view is also below it. issue view 2

1 Answers

Show the code of loading the fragment in the activity as it seems you are adding same fragment again and again.

Also if your are this intentionally you have not given background color to your fragment's root view and you should also give

android:clickable="true"
android:focusable="true"

to the root view so background fragments dont get wrong clicks.

Happy Coding

Related