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 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.