When you select the second item in the Navigation Drawer application simply collapses and the last fragment remains. Are fragments exactly needed in order to change content when choosing in Navigation Drawer ?

 public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); Fragment fr = null; if (id == R.id.nav_store) { fr = null; } else if (id == R.id.nav_plus) { fr = new psplus(); } else if (id == R.id.nav_people) { fr = null; } getSupportFragmentManager() .beginTransaction() .replace(R.id.nav_view, fr) .commit(); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } 

There are no syntax errors, all classes are in the project. What's happening?

  • In your code: .replace (R.id.nav_view, fr) - the first argument of the replace method is the container where you want to place the fragment. R.id.nav_view is a soma curtain. I think you want to put it somewhere else. And what is the last piece? You have only one kind of it, just the second - fr = new psplus (); - Michael
  • I want to place the psplus fragment in the place where the nav_view fragment is now located - Vitya Shchelochkov

0