I have activity with listView, where each element can be expanded when clicked, showing mapView. If you click another item, the open item is closed. Activity extends MapActivity, and there is only one mapview instance that I delete and add to elements as needed as follows:
private MapView getMapView() { if (mMapView == null) { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); mMapView = (MapView) inflater.inflate(R.layout.club_map,null); } else { ((ViewGroup) mMapView.getParent()).removeView(mMapView); } return mMapView; } private void attachMap(View targetView,String siteID) { if (openInPrgrs) { return; } RelativeLayout relView = (RelativeLayout) targetView.findViewById(R.id.clubDetailsLayout); LinearLayout mapContainer = (LinearLayout) relView.findViewById(R.id.mapContainer); UtilFunctions.logIfDebug("MembershipsList","Attaching Map. siteID " + siteID + " childCount = " + mapContainer.getChildCount()); if (mapContainer.getChildCount() > 0 ) { return; } MapView mapView = getMapView(); mapContainer.addView(mapView); }
It works great in most cases, but when the screen turns off and on again, or the open item scrolls from the screen and back, the mapView disappears. I know this because the view is processed by a list. If I try to attach the map in getView () (if the view is in an open position):
public View getView(int position, View convertView, ViewGroup parent) { final View resultView = super.getView(position, convertView, parent); LayoutParams lp = resultView.getLayoutParams(); if (curOpenPos == position) { LinearLayout mapContainer = (LinearLayout) resultView.findViewById(R.id.mapContainer); lp.height = item_height_open; attachMap(resultView, siteID); }
} the map disappears when the element expands completely, but when the screen goes blank and appears on it.
Does anyone know why this is happening, or what can I do to solve it?
source share