In android studio created an application using the template of the drawer. Made two fragments and generated markup for them. In MainActivity: Create two fragments

FragmentPipes fragmentPipes; FragmentTanks fragmentTanks; 

In onCreate () they initialize

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

So that when you click on the menu item to change the fragment in the container content_main.xml created FrameLayout with id container. in onNavigationItemSelected (MenuItem item) I set the action by clicking on the menu item

 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); } 

After launching the application, when you select the corresponding item in the drawer with one of these fragments, the fragment is not replaced. I do not get any errors, just nothing happens.

All code is laid out by Calculator

Closed due to the fact that the essence of the question is not clear to the participants by Vladyslav Matviienko , YuriySPb , aleksandr barakin , user194374, Denis Jul 15 '16 at 6:12 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    I don't think anyone wants to read the full code of your application. Locate the problem, and post the problem code here, do at least something on your part to solve the problem. - Vladyslav Matviienko 5:14
  • I apologize for the incorrect formulation of the problem. The first time I ask a question. The hitch is that I don’t suspect where the problem part of the code is, so I decided that it’s wrong to write sheets of the entire project’s code here. Especially considering the fact that the studio creates xml nested in each other as a nested doll. I am ready to correct the formulation as it should, only I don’t know how. - Alexander Tymchuk

1 answer 1

The problem with you is that you are not calling commit() over a fragment add transaction.

  • one
    You are absolutely right, forgot commit. Thank you very much! - Alexander Tymchuk