I am aware that there is some kind of patch for fragments for Mapsforge here: https://code.google.com/p/mapsforge/issues/detail?id=177 .However I'm not exactly sure how to use it.
This is what I've implemented so far:
public class TOfflineMapViewFragment extends SherlockFragment{
MapView myOpenMapView;
//other codes here...
public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle savedInstanceState) {
view = inflator.inflate(R.layout.offline_map_activity, container, false);
myOpenMapView = (MapView) view.findViewById(R.id.openmapview);
myOpenMapView.setMapFile(new File(Environment.getExternalStorageDirectory().toString() +
"/offlineMap/singapore.map");
return view;
}
}
This is my xml file:
<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" >
<org.mapsforge.android.maps.MapView
android:id="@+id/openmapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
I'm getting this error:
03-19 15:51:04.243: E/AndroidRuntime(10395): FATAL EXCEPTION: main
03-19 15:51:04.243: E/AndroidRuntime(10395): android.view.InflateException: Binary XML file line #6: Error inflating class org.mapsforge.android.maps.MapView
03-19 15:51:04.243: E/AndroidRuntime(10395): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
03-19 15:51:04.243: E/AndroidRuntime(10395): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-19 15:51:04.243: E/AndroidRuntime(10395): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
03-19 15:51:04.243: E/AndroidRuntime(10395): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-19 15:51:04.243: E/AndroidRuntime(10395): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-19 15:51:04.243: E/AndroidRuntime(10395): at com.fragments.TOfflineMapViewFragment.onCreateView(TOfflineMapViewFragment.java:76)
What is wrong with this?
adding
AndroidGraphicFactory.createInstance(getActivity().getApplication());
in overridden onCreate() worked for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With