我正在研究PlaceAutocompleteFragment
。我只在第一次加载此Fragment
,第二次加载时又显示了一些错误,并且崩溃了。
错误是:java.lang.IllegalArgumentException:二进制XML文件行 11:重复的ID 0x7f090251,标记为null或父ID 0x7f090193(带有另一个用于 com.google.android.gms.location.places.ui.PlaceAutocompleteFragment
public class MakeReservationFragment extends BaseFragment implements
GoogleApiClient.OnConnectionFailedListener , PlaceSelectionListener {
View mMakeReservationView;
ProgressBar bar;
FrameLayout layout;
private static final LatLngBounds BOUNDS_GREATER_SYDNEY = new
LatLngBounds(
new LatLng(-34.041458, 150.790100), new LatLng(-33.682247, 151.383362));
@Override
public View setContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mMakeReservationView = inflater.inflate(R.layout.frag_make_reservation, container, false);
initView();
return mMakeReservationView;
}
private void initView() {
setHeaderBarTitle("RESERVATION");
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getActivity().getFragmentManager().findFragmentById(R.id.place_fragment1);
autocompleteFragment.setOnPlaceSelectedListener(MakeReservationFragment.this);
autocompleteFragment.setHint("Search a Location");
autocompleteFragment.setBoundsBias(BOUNDS_GREATER_SYDNEY);
layout=(FrameLayout)mMakeReservationView.findViewById(R.id.framereserve1);
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
@Override
public void onResume() {
super.onResume();
getView().setFocusableInTouchMode(true);
getView().requestFocus();
setHeaderBarleftIcon(R.drawable.ic_home);
getView().setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
}
return false;
}
});
}
@Override
public void onPlaceSelected(Place place) {
}
@Override
public void onError(Status status) {
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0) {
if (resultCode ==RESULT_OK) {
Place place = PlaceAutocomplete.getPlace(getActivity(), data);
onPlaceSelected(place,0);
} else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
Status status = PlaceAutocomplete.getStatus(getActivity(), data);
this.onError(status,0);
}
}
else
{
if (resultCode == RESULT_OK) {
Place place = PlaceAutocomplete.getPlace(getActivity(), data);
onPlaceSelected(place,1);
} else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
Status status = PlaceAutocomplete.getStatus(getActivity(), data);
onError(status,1);
}
}
}
private void onError(Status status, int i) {
Toast.makeText(getActivity(), "Place selection failed: " + status.getStatusMessage(),
Toast.LENGTH_SHORT).show();
}
private void onPlaceSelected(Place place, int i) {
try{
System.out.println("00000000 Place Darta IS 0 error" + place.getId()+","+place.getAddress()+","+place.getLatLng()+","+place.getLocale()+","+place.getName()+
","+place.getAttributions()+","+place.getViewport()+","+place.getPhoneNumber()+","+place.getPlaceTypes());
}
catch ( Exception e)
{
}
}
}
XML代码是:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/framereserve1"
android:background="@color/backgoound_dull"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/place_fragment1"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="50dp"/>