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

GoogleMaps V2 Mapview inside tabView (SectionPagerAdapter)

Hey guys! I am new to Android development and I'd like to add a MapView fragment inside a sectionPagerAdapter (in one of the tabs).

When following the tutorial found here: https://developers.google.com/maps/documentation/android/start it works in a single View/Activity

I'd like the map to be shown in one of the tabs though. How can I accomplish this?

Thanks /Jonathan

1 Answer

First off, I had to do some digging to find out what you meant by SectionPagerAdapter as that's not an official class in the Android SDK. =D If you are looking for documentation on how to use SectionPagerAdapter, which is a class generated by the Eclipse tools, you should look at FragmentPagerAdapter here.

To get at the heart of your question, you should be able to implement the method getItem(int) in your SectionPagerAdapter and return an instance of MapFragment (or SupportMapFragment if you targeting devices older than Honeycomb) for the desired tab index (the position argument).