나는 각 항목을 클릭하면 확장되어 mapView가 표시되는 listView에 대한 작업을 수행합니다. 다른 항목을 클릭하면 미결 항목이 닫힙니다. 활동은 MapActivity를 확장하고, 내가 제거하고 다음과 같이 필요에 따라 항목에 추가지도보기 하나의 인스턴스 만이있다 :MapView의 목록보기 항목
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);
}
그것은 대부분의 시간을 잘 작동하지만 화면이 꺼질 때 다시 열거 나 열린 항목이 화면에서 뒤로 스크롤되면 mapView가 사라집니다. 보기가 listView에 의해 재활용되고 있기 때문에이 사실을 알고 있습니다. 나는 (보기가 열린 위치에있는 경우))의 getView (의지도를 첨부하려고하면 :
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);
}
} 맵 항목이 완전히 확장되면 사라지지만 화면이 꺼져과에 갈 때 나타납니다.
왜 이런 일이 발생하는지 또는 내가 해결할 수있는 방법을 알고 계십니까?
아마도 mapContainer에 싱글 톤 mapView를 추가하는 것이 고려 될 수 있지만 가시성을 고려해야합니다. 예 : 선택되어 있지 않은 행 setVisibility (View.GONE), 선택된 행 setVisibility (View.VISIBLE). 이 행동이 바뀌 었습니까? – CSmith
이 링크를 참조하십시오 http://stackoverflow.com/questions/2961275/android-mapview-contained-within-a-listview 도움이되기를 바랍니다. –