0

I have a query where I want to know whether it can be achieved or not with Navigation Controller.

Old Implementation

I have to take user info in multiple parts to make a smooth experience and keep the app a little interactive, now I have Activity A which contains two Fragments A-1 and A-2. Now I show Fragment A-1 and take part of the user info there and then on the next button I show Fragment A-2 and take the remaining info there and then process the information to store it. Pictures are attached for a better understanding:

Activity A with Fragment A-1

Activity A with Fragment A-2

New Implementation Query

Now the question is that can all this be done with Navigation Component having a Fragment A containing two child Fragments A-1 and A-2 and transitioning from Fragment A-1 to Fragment A-2.

Note:

I have recently started using the navigation component and have done a few simple examples as well as some nested graphs examples too but unable to do such tasks. I did this 2 years ago using FragmentManager but now I want to change the implementation to the best practices followed these days. Again I don't want to change the whole fragment but the child fragments (the middlebox where I take the user info) inside the parent fragment.

Muhammad Yousuf
  • 127
  • 2
  • 16
  • 1
    See if this helps: https://stackoverflow.com/a/56620939/2649154 – gioravered May 25 '22 at 08:33
  • I'll read and give it a try :) – Muhammad Yousuf May 25 '22 at 08:41
  • I read and saw the video he posted but that is now what I am trying to achieve, he adds a dialog and when showing a dialog it opens on top of the fragment not in the fragment thus creating a black shadow behind it and I don't want that. I want to change the middlebox part where I take the info to transition from one to another fragment. – Muhammad Yousuf May 25 '22 at 08:49
  • 1
    You can remove the black shadow.. Using a DialogFragment to host your "user info" window. https://stackoverflow.com/questions/13822842/dialogfragment-with-clear-background-not-dimmed – gioravered May 25 '22 at 08:54
  • I know about this, but is this a good approach? – Muhammad Yousuf May 25 '22 at 09:15
  • If you want my opinion, I would use navigation for the details dialog(s). For me this is just a view. A way for the user to insert his details. It might change tomorrow.. I would have a view model for the screen and bind the view to the view model data. – gioravered May 25 '22 at 10:21
  • Okay, l'll see if anyone else has another approach or I'll just use fragmentMangers again and bind them with the shared view model. – Muhammad Yousuf May 25 '22 at 15:33

0 Answers0