Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MapActivity in a fragment

Tags:

android

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?

like image 858
Rocío Gómez Escribano Avatar asked Jan 18 '23 04:01

Rocío Gómez Escribano


1 Answers

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

like image 190
rallat Avatar answered Feb 05 '23 01:02

rallat