0

I am developing an activity that contains a kind of mix between a menu and a progress bar. Below this, there are views that are "visible" or "gone" depending on the progress in which the user is. I have programmed everything in the same activity, but I have doubts that this is efficient because we are talking about more than 1200 lines of code and most of it is only used in part of the progress.

Do you think creating a structure with fragments would be better? If so, how would you go about changing from one fragment to the next from a button within the fragment?

enter image description here

  • I follow a simple rule: Lift shared state up via events and/or callbacks (listeners). So your activity could host fragments that do their individual jobs. Then the fragments are responsible for sending back their results to the activity. The activity can then continue or stop the flow based on received results. – ashu May 10 '21 at 10:53
  • Okay, but how can I change for example from fragment 1 to fragment 2 on click on the Next button? – Emili Bellot Pulido May 10 '21 at 10:57
  • There are two ways that I can think of on top of my head: pass a listener when creating a new instance of fragment 1, e.g. new Fragment1(OnNextClickListener() { ... }). Another way highlighted very neatly in [this answer](https://stackoverflow.com/a/18110614/2410641) where activity serves as common listener. – ashu May 10 '21 at 11:01

0 Answers0