2014-01-14 5 views
0

내 응용 프로그램에 MapFragment 및 일반 Fragments가 있습니다. 문제는 내가 조각 사이를 갈 때, MapFragment가 백그라운드에있는 것입니다. MapFragment가 있는지 확인하는 코드가 있지만 코드를 제거해야합니다.MapFragment를 제거하십시오

코드 :

FragmentMapView mapFragmentcheck = (FragmentMapView)getFragmentManager().findFragmentByTag("map"); 
if (mapFragmentcheck != null) { 
    Log.d("tag","max exists"); 
    if (mapFragmentcheck.isVisible()) { 
     Log.d("tag","map is visble, remove it");  
     // Do remove here, but how? 
    } 
} 
else { 
    Log.d("tag","map does not exists"); 
} 

답변

1

코드는 다음과 같습니다

getFragmentManager().beginTransaction().remove(mapFragmentcheck).commit(); 

는 조각을 변경하는 방법에 대한 자세한 내용을 이해하기 위해 FragmentTransaction에 설명서를 참조하십시오.

+0

Ah finnaly. 그것은 작동, 당신은 내 하루를 구했습니다. –

+0

당신을 진심으로 환영합니다. BTW : 해결 된 질문에 [해체]를 추가 할 필요가 없습니다. 간단히 대답을 받아 들여 가장 도움이되었습니다. 사이트가 나머지 부분을 처리합니다. 또한 수용도가 높으면 사람들이 귀하의 질문에 답할 확률이 높아집니다. – keyboardsurfer

2

이 같은

내가 추가 된 구글지도 나를 위해 일한이

@Override 
 
public void onDestroyView() { 
 
\t super.onDestroyView(); 
 
\t MapFragment mapFragment = (MapFragment) getActivity() 
 
\t \t \t .getFragmentManager().findFragmentById(R.id.map_add_place); 
 
\t if (mapFragment != null) 
 
\t \t getActivity().getFragmentManager().beginTransaction() 
 
\t \t \t \t .remove(mapFragment).commit(); 
 
}

0

을보십시오이

XML에서 내지도이

과 같은

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    View v = inflater.inflate(R.layout.home_fragment, container, false); 
    Bundle bdl = getArguments(); 

    // setuping locatiomanager to perfrom location related operations 
    locationManager = (LocationManager) getActivity().getSystemService(
      Context.LOCATION_SERVICE); 

    // Requesting locationmanager for location updates 
    locationManager.requestLocationUpdates(
      LocationManager.NETWORK_PROVIDER, 1, 1, this); 

    // To get map from MapFragment from layout 
    googleMap = ((MapFragment) getActivity().getFragmentManager() 
      .findFragmentById(R.id.map)).getMap(); 

    // To change the map type to Satellite 
    // googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); 

    // To show our current location in the map with dot 
    // googleMap.setMyLocationEnabled(true); 

    // To listen action whenever we click on the map 
    googleMap.setOnMapClickListener(new OnMapClickListener() { 

     @Override 
     public void onMapClick(LatLng latLng) { 
      /* 
      * LatLng:Class will give us selected position lattigude and 
      * longitude values 
      */ 
      Toast.makeText(getActivity(), latLng.toString(), 
        Toast.LENGTH_LONG).show(); 
     } 
    }); 

    changeMapMode(3); 

    // googleMap.setSatellite(true); 
    googleMap.setTrafficEnabled(true); 
    googleMap.setBuildingsEnabled(true); 
    googleMap.setMyLocationEnabled(true); 

    return v; 
} 
이 같은개
<fragment 
     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.MapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:tag="ScrewMaps" /> 

내가 분리하고 조각 : -

@Override 
    public void onDestroyView() { 
     // TODO Auto-generated method stub 
     super.onDestroyView(); 

     locationManager.removeUpdates(this); 

     android.app.Fragment fragment = getActivity().getFragmentManager() 
       .findFragmentById(R.id.map); 
     if (null != fragment) { 
      android.app.FragmentTransaction ft = getActivity() 
        .getFragmentManager().beginTransaction(); 
      ft.remove(fragment); 
      ft.commit(); 
     } 
    } 

내지도보기 조각이 android.app.Fragment & 나는() 추가하고 MapViewFragment을 제거하기 위해 getFragmentManager을 사용하고 있음을 유의하시기 바랍니다. V4.Fragment 작업을 app.Fragment와 혼합하면 앱이 심하게 다운됩니다.