Android: PlaceAutomcompleteFragment working but not going off after its usage -


in activity, using placeautocompletefragment. have defined in main layout xml. once use of placeautocoplete fragment done. not able off view.

<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 > 

this activity code:

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 error.                 //   log.i(tag, "an error occurred: " + status);             }         });          } 

so once onplaceselectedlistener finishes want destroy fragment or take off view. causing hindrance ehatever add view. making new layout xml helpful.

remove fragment @ ondestroyview()

@override  public void ondestroyview() {       super.ondestroyview();      fragmentmanager fm = getactivity().getfragmentmanager();      fragmenttransaction ft = fm.begintransaction();      ft.remove(autocompletefragment).commit(); } 

Comments