2016-03-26 12 views
0

私の活動では、PlaceAutoCompleteFragmentを使用しています。私はそれをレイアウトXMLのメインに定義しました。 placeautocopleteフラグメントの使用が完了したら。私はそれを見ることができません。Android:PlaceAutomcompleteFragmentは動作していますが、使用後には消えません。

<FrameLayout 
    android:id="@+id/fragment_container" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="horizontal" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:map="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/map" 
    android:name="com.google.android.gms.maps.SupportMapFragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.jawadh.startthreeproject.MapsActivity" /> 
    <fragment 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/place_autocomplete_fragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" 
     /> 
</FrameLayout > 

これが私の活動のコードです:

final PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment); 

    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() { 

     public void onPlaceSelected(Place place) { 
      String placeDetailsStr = place.getName() + "\n" 
        + place.getId() + "\n" 
        + place.getLatLng().toString() + "\n" 
        + place.getAddress() + "\n" 
        + place.getAttributions(); 

      m.setPosition(place.getLatLng()); 
      m.setTitle(place.getName().toString()); 


mMap.moveCamera(CameraUpdateFactory.newLatLng(place.getLatLng())); 
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLng(), 17.0f)); 

       } 

      public void onError(Status status) { 
       // TODO: Handle the error. 
       // Log.i(TAG, "An error occurred: " + status); 
      } 
     }); 

     } 

ので、私はただの断片を破壊またはビューをそれを取るしたいOnPlaceSelectedListenerが終了したら。それは、何かを見ることに支障をきたす。新しいレイアウトxmlを作ることも役に立ちます。

答えて

0

onDestroyView()

@Override 
public void onDestroyView() { 
    super.onDestroyView(); 
    FragmentManager fm = getActivity().getFragmentManager(); 
    FragmentTransaction ft = fm.beginTransaction(); 
    ft.remove(autocompleteFragment).commit(); 
} 
でフラグメントを削除します
関連する問題