user31231234124 user31231234124 - 1 month ago 12
Android Question

First fragment is visible even after transacting the second fragment

The following fragment will be done when the user clicks the first item in the navigation view

android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
Dashboard newFragment = (Dashboard) fm.findFragmentByTag("viewAlbum");
if (newFragment == null) {
newFragment = new Dashboard();
}
fm.beginTransaction()
.replace(R.id.content_frame, newFragment, "viewAlbum")
.show(newFragment)
.commitAllowingStateLoss();
supportInvalidateOptionsMenu();


The following fragment will be loaded when the user clicks the second item in navigation view.

android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
AssigneewiseFragment newFragment = (AssigneewiseFragment) fm.findFragmentByTag("viewSelectedPlaylist");
if (newFragment == null) {
newFragment = new AssigneewiseFragment();
}
fm.beginTransaction()
.add(R.id.content_frame, newFragment, "viewSelectedPlaylist")
.show(newFragment)
.addToBackStack(null)
.commitAllowingStateLoss();


The issue is that When the user clicks the second item in navigation view, the assigneewise fragment is loaded but still the first fragment is visible below the second fragment. How can I be able to sort this out?

Answer

I don't think replace() will solve your problem

for that you need to set background color white or anything and you need to use click listener on your main layout.