Why don't they see fragments in the container?



  • In android studio, an application has been created with a drawer. Got two fragments and edited the marking for them. In MainActivity: I'm building two fragments.

    FragmentPipes fragmentPipes;
    FragmentTanks fragmentTanks;
    

    In onCreate(s)

    fragmentPipes = new FragmentPipes();
    fragmentTanks = new FragmentTanks();
    

    In order to change the fragment in the content container...main.xml created FrameLayout from id container. in onNavigationItemSelected(MenuItem item) apply to the menu point

    int id = item.getItemId();
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    if (id == R.id.nav_pipes) {
        fragmentTransaction.replace(R.id.container, fragmentPipes);
    } else if (id == R.id.nav_tanks) {
        fragmentTransaction.replace(R.id.container, fragmentTanks);
    }
    

    Once the application has been launched, one of these fragments does not replace the fragment when choosing to drawer. I don't get any mistakes, but nothing happens.

    The whole code is out. https://github.com/Zets-swe/Calculator



  • Problem is, you're not calling. commit() above the transaction of the addition of a fragment




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2