0

I've implemented a NavigationDrawer within the MainActivity which containts two Fragment. The second Fragment contains a ListView that opens a new Activity (onItemClick) that shows the according detailed data. (I guess that's pretty much the master/detail flow).

When I use the up button to navigate back I got shown the first fragment and not the second fragment with the ListView.

Any ideas how to solve that problem?

Kody
  • 1,154
  • 3
  • 14
  • 31
  • have you overriden onBackPressed ? – Darko Rodic Mar 04 '14 at 10:06
  • Not yet, but I see it's for the case the user pressed the BACK key, isn't it? I'm looking for a solution to get to the last fragment when the user pressed UP in the ActionBar. – Kody Mar 04 '14 at 10:11
  • then I believe you have everything you need here: https://developer.android.com/training/implementing-navigation/ancestral.html – Darko Rodic Mar 04 '14 at 10:17
  • I already implemented `NavUtils.navigateUpFromSameTask(this); return true;` within `optionsItemSelected`. It just takes the user back to MainActivity - first fragment. – Kody Mar 04 '14 at 10:22
  • well, then make method in MainActivity for example setFragment(int whichFragment) ... and set fragment you want in it, you should already have code that do that and than call that method from onback – Darko Rodic Mar 04 '14 at 10:24
  • some feedback would be nice :) if you still cant figure this out, provide some codez and I will help you – Darko Rodic Mar 04 '14 at 10:33
  • I see that your solution will work. Thank you. If you post it as an answer I can mark it as solved. Nevertheless I'm wondering if a new Activity is the right way to implement the master/detail flow. Wouldn't be the usage of another fragment for the details more appropriate? – Kody Mar 04 '14 at 10:49

1 Answers1

1

Make method in MainActivity for example setFragment(int whichFragment); and set fragment you want in it, you should already have code that do that and than call that method in onBackPressed() method.

For your question about another fragment, well it depends on how your master/detail flow is suppose to work, it is not a problem to use another activity if you dont need left menu any more, but if you do need left menu then use another fragment.

Best regards

Darko Rodic
  • 1,010
  • 3
  • 10
  • 27