问题描述
我在我的项目中使用 Android版Google Places API-PlaceAutocompleteFragment API来搜索位置,当用户选择一个位置后,使用经纬度的位置获取记录,并将其显示在ListView中.
现在的问题是,只要用户点击 PlaceAutocompleteFragment 我想清除需要收听清除按钮onClick的ListView项吗?该怎么做?
任何帮助将不胜感激.
I am using Google Places API for Android - PlaceAutocompleteFragment API in my project to search locations, when user selects a location then get the records using location lat-long and display it to ListView.
Now the problem is whenever user taps on clear button (X) of PlaceAutocompleteFragment I want clear ListView items for which I need to listen to clear button onClick? How to do that?
Any help will be appreciated.
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
LatLng latLng=place.getLatLng();
//hit web service, response parsing and add it to listview.
}
@Override
public void onError(Status status) {
Log.i(TAG, "An error occurred: " + status);
}
});
推荐答案
查看PlaceAutocompleteFragment
的源代码,我发现了这些视图id并设置了onClickListener
像这样:
Looking at the source code of PlaceAutocompleteFragment
I found those view ids and setup a onClickListener
like this:
autocompleteFragment.getView().findViewById(R.id.place_autocomplete_clear_button)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// example : way to access view from PlaceAutoCompleteFragment
// ((EditText) autocompleteFragment.getView()
// .findViewById(R.id.place_autocomplete_search_input)).setText("");
autocompleteFragment.setText("");
view.setVisibility(View.GONE);
}
});
这篇关于Android Google Places API-PlaceAutocompleteFragment清除按钮侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!