0

this is a similar question to: MapFragment in Action Bar Tabs but there wasn't a clear answer from this that I understood. I am new to Android and this is my first application Im developing .

I currently have one MainActivity that creates a MapFragment for Google Maps v2. and displays a map under an ActionBar as shown in this screenshot

My objective is to implement tabs (Not using FragmentActivitys or the support Library as my application is minSdkVersion=11) for the MainActivity in Eclipse which currently creates a MapFragment for Google Maps v2.

MainActivity.java snippet

public class MainActivityextends Activity 
implements LocationListener, LocationSource, OnMarkerClickListener, OnInfoWindowClickListener {
    private static GoogleMap googleMap;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map); 
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); //Change to Tab mode 
        ....
        googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();


map.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <include 
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    layout="@layout/map_fragment" />
</LinearLayout>


map_fragment.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraTargetLat="53.78513542767"
map:cameraTargetLng="-3.14948167651"
map:cameraZoom="14" />


Eclipse sets up tabs for you with an Activity using the support library so it gave me an error(below) when using a MapFragment and I reverted back to not using tabs. Reason for this I think is here

Caused by: java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment

I need to use tabs as currently only one page/activity has been developed and I need a way to display filters to the user as well as the map. The user will switch to the adjacent tab to edit filters and be able to switch back to the Map tab where the filters will then be picked up and alter the markers on the map.

So short question is there a simple way for me to implement tabs for my MainActivity.java? If this isnt clear just ask me specifics but this is very advanced for me

Community
  • 1
  • 1
Jethro
  • 928
  • 1
  • 10
  • 20

1 Answers1

0

try using SupportMapFragment instead of MapFragment:

map.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraTargetLat="53.78513542767"
map:cameraTargetLng="-3.14948167651"
map:cameraZoom="14" />
comeGetSome
  • 1,913
  • 19
  • 20