0

I have a navigation drawer with few contents. On click selected navigation content i'm adding ListFragment into activity container. When i clicked on the selected ListFragment position i want to show detail of this selected content. What is the better approach:

  1. Replace the MainActivity container(which is ListFragment) by DetailFragment.

  2. New DetailActivity which include the DetailFragment. Or there is a other approach.

Spyker
  • 15
  • 1
  • 8

3 Answers3

0

So you essentially need to have a ChildFragment inside your ListFragment

Use getChildFragmentManager() inside your ListFragment for your DetailFragment transactions. This is the best approach if you need to notify anything to your ListFragment from your DetailFragment in future. So your activity will just have the fragment holder for your ListFragment. Your ListFragment will have the fragment holder for your child fragments, in your case, DetailFragment.

Having a separate DetailActivity for each list view click is good but not the best approach as you will lose your ListActivity context then.

For reference : https://stackoverflow.com/a/17132254/1115353

Community
  • 1
  • 1
Bharath Mg
  • 1,117
  • 1
  • 9
  • 18
0

I believe in the most of cases it's better to replace old fragment with a new one when you are switching between drawer menu items. If you go deeper in already existing fragment on MainActivity you should use "add" method with saving fragments in stack.

If you want to change content from Drawer - it's better to replace fragment. If you want to add new content above existing, like adding details, you should use "add" method

Tieru
  • 1,360
  • 1
  • 10
  • 16
0

The second approach is the better, where the Gmail app uses that approach.

enter image description here

enter image description here

Mahmoud Ibrahim
  • 1,057
  • 11
  • 20