android - 当第二次加载 GooglePlaceAutocomplete Fragment 时它崩溃了
问题描述
我正在努力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"/>
解决方案
推荐阅读
- deployment - 如何更新 Kubernetes 部署映像和命令?
- ios - 用于写入更大 CSV 文件的 CHCSVWriter 内存使用情况
- c# - 我如何调试在外部 C# 应用程序中 SWIGed 的 C++ DLL(不能从调试器启动)
- python - 我尝试使用刮刀从页面中提取内容时出错
- javascript - 捕捉回调异步函数完成的时刻
- flutter - Dismissible widget animation overlaps page push animation
- excel - 使用 oXMLFile.SelectNodes 的唯一节点值
- scala - 当字符串也包含UDF时,如何将List [String]传递给spark中的select或selectExpr
- java - jDeveloper ...无法让已部署的 jar 工作(缺少库?)
- c# - 绑定到 WPF DataGrid 并支持排序时使用数据虚拟化