I have a navigation drawer. In the listView I select the item replace fragment1 , in fragment1 I select item from the list and replace fragment1 with fragment2 ...

How to go back in fragments? By pressing the left top of the button, the navigation drawer opens. This all happens in one activity. Am I doing this right? Is there an example?

    1 answer 1

    That just (a minute ago) solved a similar problem.

    What we need:

    1) When you start the activation show a hamburger.

    2) When replacing the fragment, change the hamburger to the arrow.

    3) When you click on the arrow to return the previous fragment

    4) Again show the hamburger.


    We do:

    1) If the ND is done correctly, then the hamburger is already shown at launch.

    2) You can show the arrow like this:

     mDrawerToggle.setDrawerIndicatorEnabled(false); 

    3, 4) It will respond to clicking in onOptionsItemSelected () by id R.id.home

     @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: //При нажатии вызывается обработчик кнопки назад //Он по умолчанию должен будет вернуться по списку фрагментов назад onBackPressed(); //Надо вернуть иконку гамбургера mDrawerToggle.setDrawerIndicatorEnabled(true); return true; } } 

    PS Here we solved a similar problem in the Anglo-Saxon.

    • one
      Thanks for the link, everything works fine. At the same time I learned a couple of useful methods! - abbath0767
    • Please give working code. I have ND, from my home frame I replace it with a "more type of card" frame; there is a back arrow, but it is not pressed. - pl_roman
    • Shows the arrow ((AppCompatActivity) getActivity ()). GetSupportActionBar (). SetDisplayHomeAsUpEnabled (true); - I call from the frame. But pressing the arrow climbs the menu. - pl_roman
    • @pl_roman, points 3 and 4 have been made? - Yuriy SPb