Ste*_*pan 1 android google-maps autocompletetextview google-maps-android-api-2
我想实现AutocompleteTextView(谷歌地方),但是当我点击片段中的searchView时,片段消失(摔倒).
我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_autocomplete);
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
.setTypeFilter(AutocompleteFilter.TYPE_FILTER_CITIES)
.build();
autocompleteFragment.setFilter(typeFilter);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(com.google.android.gms.location.places.Place place) {
// TODO: handle click
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
}
});
}
Run Code Online (Sandbox Code Playgroud)
XML:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="ui.screen.activity.AutocompleteActivity">
<fragment
android:id="@+id/place_autocomplete_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
谢谢你的建议
小智 6
我有同样的问题.我搞砸了API控制台 https://console.developers.google.com/,启用了Maps API 和 Places API for Android,现在它运行正常.
| 归档时间: |
|
| 查看次数: |
2587 次 |
| 最近记录: |