Good night, I'm creating an app to train and it contains side menu that each menu item calls a Fragment but I'm in trouble, because when I click on an item it appears the called fragment, but when I click on the other item the second fragment is superimposed on the first, so I can not make the disappearance of the first fragment .... I looked for some solution on the internet, and there is a user here that asked the same question, I tried to follow the same procedure but I could not ... Can anyone help me?
code xml:
<fragment
android:id="@+id/fragments"
android:name="com.nathan.lotogera.lotogera.Fragments.DuplaSena"
android:layout_width="match_parent"
android:layout_height="match_parent" />
code java:
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
DuplaSena duplaSena = new DuplaSena();
fragmentTransaction.replace(R.id.fragments, duplaSena, duplaSena.getTag());
fragmentTransaction.commit();
} else if (id == R.id.nav_slideshow) {
Quina quina = new Quina();
fragmentTransaction.replace(R.id.fragments, quina, quina.getTag());
fragmentTransaction.commit();
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
Thank you ....