4

I have a FragmentActivity:

public class parking extends FragmentActivity { }

It has 3 tabs, the second and third are lists, solved.

public class tab2 extends Fragment{ }

But the first one is a map, so, I can't extend Fragment and a MapActivity.

How can I solve it?

skynet
  • 9,898
  • 5
  • 43
  • 52
  • If you're using the compatibility apis I think you have to make another activity that uses MapActivity, there is MapFragment if you're using 3.0+ apis – FunkTheMonk Nov 30 '11 at 11:03
  • Thank you very much. You said something interesting for me, can I show a map in my app whith minSDKVersion = 8??? thanks! – Rocío Gómez Escribano Nov 30 '11 at 14:32
  • Possible duplicate of http://stackoverflow.com/questions/5109336/mapview-in-a-fragment-honeycomb – skynet Nov 30 '11 at 22:05

2 Answers2

5

There is no support for MapFragment, Android team says is working on it since Android 3.0. Here more information about the issue http://code.google.com/p/android/issues/detail?id=15347&utm_source=buffer&buffer_share=acc72 But what you can do is create a Fragment that returns a MapActivity. Here is a code example. Thanks to inazaruk: https://github.com/inazaruk/examples/tree/master/MapFragmentExample How it works:

  • MainFragmentActivity is the activity that extends FragmentActivity and hosts two MapFragments.
  • MyMapActivity extends MapActivity and has MapView.
  • LocalActivityManagerFragment hosts LocalActivityManager.
  • MyMapFragment extends LocalActivityManagerFragment and with help of TabHost creates internal instance of MyMapActivity.

if you have any doubt please let me know

rallat
  • 1,275
  • 1
  • 10
  • 16
  • Map Api version 2 supports now Map Fragment https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/SupportMapFragment – rallat Feb 02 '13 at 00:33
4

Google released the Map API Version 2. This finally allows us to use a MapFragment and a SupportMapFragment. This allows adding Maps to ViewPagers and to Activities that do not extend MapActivity.

Janusz
  • 187,060
  • 113
  • 301
  • 369