1

So, I'm trying to put together some fragments. I have a TabActivity extending FragmentActivity
Inside the TabActivity i have 4 tabs that extend Fragments(android.support.v4.app.Fragment)
In one of these Fragments i want a google map to take up some part of the screen. I have ViewPager to switch between views within the TabActivity. In my project i have
Android Private Libraries
-Google-play-services.jar -android-support-v4.jar

And my manifest has my unique API key.

BUT, when i press the tab that should hold a map, i get an empty screen:

The layout

The Fragment containing the map:

public class MyTripsFragment extends Fragment 
{

private SupportMapFragment fragment;
private GoogleMap map;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
    {
        try{
            return inflater.inflate(R.layout.view_mytrips, container, false);
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        FragmentManager fm = getChildFragmentManager();

        fragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
        if(fragment == null)
        {
            fragment = SupportMapFragment.newInstance();
            map = fragment.getMap();
            fm.beginTransaction().replace(R.id.map, fragment).commit();
        }
}  

And the XML(From what i've read should NOT contain a Fragment because of my viewpager,
IllegalStateException when replacing a Fragment)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:id="@+id/mapContainer">
    <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:id="@+id/map">
    </RelativeLayout>
</RelativeLayout>  

So how can i get the map to load a map? Am i missing something small or am i going about this the wrong way? I've tried alot of different things but nothing gets me what i want.

Community
  • 1
  • 1
Jarvis
  • 312
  • 3
  • 12
  • 1
    try to uninstall the application from ur device and check whether u have added all the permission in the manifest.If possible share the code of your manifest file. – Terril Thomas Nov 04 '13 at 11:49
  • 1
    you are getting the MapView but not the map, chances are that you have wrong API key. or you would have not added your `SHA1;package.name` in console. – VenomVendor Nov 04 '13 at 11:51
  • FWIW, here is a sample app showing multiple `SupportMapFragment`s, each as pages in a `ViewPager`: https://github.com/commonsguy/cw-omnibus/tree/master/MapsV2/Pager – CommonsWare Nov 04 '13 at 13:11

0 Answers0