Note that there are some explanatory texts on larger screens.

plurals
  1. POMapView in a listView item
    text
    copied!<p>I have an activity with a listView, where each item can be expanded when clicked, showing a mapView. If another item is clicked, the open item is closed. The activity extends MapActivity, and there is only one instance of mapview, which I remove and add to the items as needed like this:</p> <pre><code>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() &gt; 0 ) { return; } MapView mapView = getMapView(); mapContainer.addView(mapView); } </code></pre> <p>It works fine most of the time, but when the screen turns off and back on, or the open item is scrolled off screen and back, the mapView disappears. I know this is because the view is being recycled by the listView. If I try to attach the map in getView() (if the view is in the open position):</p> <pre><code>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); } </code></pre> <p>} the map disappears when the item is fully expanded, but when the screen goes off and on it does appear. </p> <p>Anyone know why this happens, or what I can do to solve it?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload