V2 cards with viewPager

I am currently developing Android 4.3.
Background:
I use pageViewer to scroll between three different fragments. My second snippet (tab 2) has XML with SupportMapFragment support and other content. as below:
My problem is http://imageupload.co.uk/files/vrhg1e06x977rkm1vhmd.jpg
My attempt:
When searching the web, I noticed that for SupportMapFragment I need a FragmentActivity, which is not applicable for the FragmentPagerAdapter. I need the user to be able to control the map, as well as control the rest of the content in the fragment.
My question is:
How can I use SupportMapFragment with viewPager, having more content in the Snippet?

More about my code: in getItem inside the FragmentPagerAdapter I return Singleton Fragments (each Fragment has a class), so I could not find any solution over the Internet, because my class cannot extend SupportMapFragment because it has more data.

+7
android android-viewpager android-maps-v2
source share
1 answer

Starting with Android 4.2 (also in the support library for pre-jelly) you can use nested fragments .

You can see how to create such a fragment:

public class MyFragment extends Fragment { private SupportMapFragment fragment; private GoogleMap map; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.layout_with_map, container, false); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); FragmentManager fm = getChildFragmentManager(); fragment = (SupportMapFragment) fm.findFragmentById(R.id.map_container); if (fragment == null) { fragment = SupportMapFragment.newInstance(); fm.beginTransaction().replace(R.id.map_container, fragment).commit(); } } @Override public void onResume() { super.onResume(); if (map == null) { map = fragment.getMap(); map.addMarker(new MarkerOptions().position(new LatLng(0, 0))); } } } 

The above code is copied from here .

Note: the custom Fragments layout cannot contain the <fragment> .

+21
source share

All Articles