在我的活动中,我正在使用PlaceAutoCompleteFragment。我在主要的Layout XML中定义了它。一旦完成了placeautocoplete片段的使用。我无法将其从视野中解脱出来。
<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 :(得分:0)
删除onDestroyView()
@Override
public void onDestroyView() {
super.onDestroyView();
FragmentManager fm = getActivity().getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.remove(autocompleteFragment).commit();
}