Java PlaceAutocompleteFragment不适用于Android 5.0&;向上的
我想在我的应用程序中使用Java PlaceAutocompleteFragment不适用于Android 5.0&;向上的,java,android,android-fragments,google-places-api,Java,Android,Android Fragments,Google Places Api,我想在我的应用程序中使用PlaceAutocompleteFragment 我成功地实现了PlaceAutocompleteFragment,并且工作正常。(在三星S4和HTC Desire中) 但当我在安卓5.0(Mi4i)和安卓5.1.1(三星Galaxy Note 10.1)中检查此功能时,和安卓6.0(Moto G Turbo)应用程序崩溃了 我在片段中使用了下面的代码,它是实现位置选择监听器 PlaceAutocompleteFragment autocompleteFragment
PlaceAutocompleteFragment
我成功地实现了PlaceAutocompleteFragment
,并且工作正常。(在三星S4和HTC Desire中)
但当我在安卓5.0(Mi4i)和安卓5.1.1(三星Galaxy Note 10.1)中检查此功能时,和安卓6.0(Moto G Turbo)应用程序崩溃了
我在片段
中使用了下面的代码,它是实现位置选择监听器
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.autocomplete_fragment);
autocompleteFragment.setOnPlaceSelectedListener(this);
@Override
public void onPlaceSelected(Place place) {
Toast.makeText(getActivity(), "Place selection : " + place.getAddress(),
Toast.LENGTH_SHORT).show();
}
/**
* Callback invoked when PlaceAutocompleteFragment encounters an error.
*/
@Override
public void onError(Status status) {
Toast.makeText(getActivity(), "Place selection failed: " + status.getStatusMessage(),
Toast.LENGTH_SHORT).show();
}
在XML布局文件中
<fragment
android:id="@+id/autocomplete_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
从堆栈跟踪来看,您似乎正在使用嵌套在另一个片段(FragmentSearchPlace)中的自动完成片段。可能使用而不是
getFragmentManager()
会起作用。您不会通过布局中的属性“name”将片段添加到其他片段中。您必须使用:
autocompleteFragment = new SupportPlaceAutocompleteFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragme_autocomplete_destino,autocompleteFragment);
transaction.commit();
调用需要API级别17(当前最小值为15):android.app.Fragment#getChildFragmentManager
。但是我的最小sdk是15。我想为sdk 15及以上提供支持。嘿,感谢您指出getChildFragmentManager()。如果我更改API级别,它工作正常。但是我想要API级别15。有没有办法做到这一点?看这里:你找到解决办法了吗?从播放服务位置:8.x
更新到9.x时,我也遇到同样的问题
autocompleteFragment = new SupportPlaceAutocompleteFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragme_autocomplete_destino,autocompleteFragment);
transaction.commit();