Home > OS >  Navigation with abstract base fragment
Navigation with abstract base fragment

Time:09-22

I have a setup like the navigation graph below. The 3 fragments in the middle are very similar and all extend a BaseFragment class.

enter image description here

What I would like to do is to make BaseFragment abstract, so that my navigation graph can be reduced to the figure below.

enter image description here

Is this even possible? It would drastically reduce the clutter of my navigation graph, because there will eventually be upwards of 20 children. However, I think this improvement would require me to instantiate an abstract class, which isn't possible.

CodePudding user response:

No, a Fragment cannot be abstract.

The solution I decided upon was to have a helper class that stores the data I want to display in my Fragment. This helper class has a child for each of the original ChildFragment classes.

I can dynamically population my Fragment by simply reading the data stored in this helper class, thus allowing me to implement the second figure in the question.

  • Related