Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Leonardo Fettucciari
Leonardo Fettucciari
633 Points

Fragments or else?

I'm thinking about making an App where the user has different mines, and to switch to a different one, he just needs to swipe left or right.

I've made a Mine Class in order to have some mVariables for each Mine. But when I want to add these mines in this TabView, should I have a single Layout for all of my mines? If so, should I make a fragment for every Mine?

I'm trying to focus on the MVC method, so should I create a Class for each Mine or as I said before, a single Fragment that can then get the Data somehow?

Any tip to get in the right direction is very well appreciated!

1 Answer

Joe Brown
Joe Brown
21,465 Points

Based on what I think you are trying to do I would definitely set up a way to reuse the view aspect of things and just fill it in with new data as needed. Creating an entirely new Fragment for each "Mine" you add would probably be a terrible design choice. What if you wanted to keep adding more later on. There's no sense in having say 50 Fragment classes that basically do the same thing. Maybe setup some inheritance if needed but I would setup a way to populate that main UI view that choose with new data as needed.

Leonardo Fettucciari
Leonardo Fettucciari
633 Points

Totally agree! I've started taking a look at this guide here: https://guides.codepath.com/android/ViewPager-with-FragmentPagerAdapter#define-fragments I'm trying to make a single MineFragment, with a single layout, and then I think I should be able to construct a new mine each time I need with the proper data and add it to the ViewPager correctly. Isn't it? What do you say Joe? I think you understood what I'm trying to do!