我正在尝试使用单一方法的MapView。
这里我创建一次MapView并且只执行一次mapViewSingletonInstance.onCreate(savedInstance)。在此之后我尝试使用它做另一个MapViewObject.addView(mapViewSingletonInstance)
但这只能运作一次。用另一个MapView添加到一个mapView后,它不起作用。
public class GoogleMapSingleton{
private static GoogleMapSingleton googleMapSingleton;
private static MapView singletonMapView;
private GoogleMapSingleton()
{
}
public static GoogleMapSingleton GoogleMapSingletonInstance(Bundle savedInstanceState, Context context)
{
if(googleMapSingleton == null){
singletonMapView = new MapView(context);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
singletonMapView.setLayoutParams(lp);
singletonMapView.onCreate(savedInstanceState);
singletonMapView.onResume();
singletonMapView.getMap();
googleMapSingleton = new GoogleMapSingleton();
}
return googleMapSingleton;
}
/**
* @return the singletonMapView
*/
public MapView getSingletonMapView() {
return singletonMapView;
}
}