Set Googlemapoptions For The Mapfragment Subclass
There is a method MapFragment.newInstance(options) The problem is that I have my own CustomMapFragment which is subclass of MapFragment and I don't see how I can set GoogleMapOpt
Solution 1:
So the correct solution was to look inside Android source code. After this I came up with this method:
publicstatic CustomMapFragment newInstance(GoogleMapOptions options) {
CustomMapFragmentf=newCustomMapFragment();
Bundleargs=newBundle();
args.putParcelable(MAP_OPTIONS, options);
f.setArguments(args);
return f;
}
Solution 2:
You can use composition instead of inheritance (Composition vs inheritance) and come up with something like this:
publicclassMyMapFragmentextendsFragment {
private MapFragment mapFragment; // google's map fragmentpublicMyMapFragment() {
this.mapFragment = MapFragment.newInstance();
}
publicMyMapFragment(GoogleMapOptions options) {
this.mapFragment = MapFragment.newInstance(options);
}
// delegate other methods to mapFragment
}
Post a Comment for "Set Googlemapoptions For The Mapfragment Subclass"