I have a tab-based android application. There is a main activity that controls 5 fragments, each fragment is a tab in the application.
All tabs in my application are very similar to one another and share a number of properties and methods.
There are a couple issues I am having though. I thought about making a parent fragment class that each fragment could inherit from, since all tabs have similar properties such as a tabName
, tabNumber
, numOfCheckBoxes
, things like that. However, whenever I switch tabs, my FragmentPagerAdapter
returns a new instance of the fragment corresponding to the tab I clicked. This means that I have to make all of my tab variables static so that they persist through switching tabs. My main activity needs to be able to view information about a specific tab even when I have left that tab and moved on to another.
Now the problem with this is that if I make a static variable in the parent class, then that property is shared amongst all tabs, which I can't have.
Is this bad design? I am very confused on how to structure my tab based app so that I am not rewriting a bunch of code, but also knowing information about each tab even while that tab may not be active.
Aucun commentaire:
Enregistrer un commentaire