I need to work back to API level 8. I have multiple activities and am using a navigation drawer to move between them as well as an action bar (with AppCompat v7). I have created a base abstract class that has all the navigation drawer setup and handling and that descends from ActionBarActivity.
File BaseNavActivity.java
abstract class BaseNavActivity extends ActionBarActivity {
}
All my activities subclass BaseNavActivity, and they all work fine.
public class MainActivity extends BaseNavActivity {
}
Before I added the navigation drawer feature I had a map working fine when descending from FragmentActivity. However, I cannot do that anymore because I need to descend from my BaseNavActivity. Even though the docs say ActionBarActivity descends from FragmentActivity I get an error when trying to use this XML.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background" >
<!-- The main content view -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:orientation="vertical"
>
<include layout="@layout/common_toolbar" />
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="3dip"
/>
<include layout="@layout/common_footer" />
</LinearLayout>
<!-- The navigation drawer -->
<include layout="@layout/nav_menu" />
</android.support.v4.widget.DrawerLayout>
I get an InflateException: Binary XML file line #19: Error inflating class fragment.
I have tried other solutions such as having a separate XML file with just the and opening it as a fragment and adding it to the above in place of the . That approach always returned a null when I tried to point to the map (smf was always null):
SupportMapFragment smf = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
I also tried to have a
public class MapFragment extends FragmentActivity {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View myFragmentView = inflater.inflate(R.layout.location_map, container, false);
return myFragmentView;
}
}
but I couldn't add the fragment using
MapFragment mapFragment = new MapFragment();
fragmentTransaction.add(R.id.map_container, mapFragment);
fragmentTransaction.commit();
The add() function needed to have parameters of (int, Fragment).
Any help will be appreciated. If you need more code I can add it but didn't want to make this post too long. I have spent a couple of days searching and trying various approaches and nothing seems to get everything working together.
Basically I would like to know how to have a <fragment>
inside the XML when descending from a custom subclass that descends from ActionBarActivity. My 2nd choice would be to know how to add a fragment that holds the map and works with the support libraries.
Thanks!