Android setOnItemClickListener在地图中不起作用

时间:2018-09-01 13:50:25

标签: android google-maps

在我的Android应用中,有一个AutoCompleteTextView来查找位置。

    private AutoCompleteTextView etHekimAra;

我这样初始化

        etHekimAra=(AutoCompleteTextView) view.findViewById(R.id.etHekimAra);

     etHekimAra.setOnItemClickListener(mAutoCompleteClickListener);

我的自动填充侦听器代码在这里:

 private AdapterView.OnItemClickListener mAutoCompleteClickListener= new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

        hideSoftKeyboard();

        final AutocompletePrediction item=mPlaceAutocompleteAdapter.getItem(i);
        final String placeId=item.getPlaceId();

        PendingResult<PlaceBuffer> placeResult= Places.GeoDataApi.getPlaceById(mGoogleApiClient,placeId);
        placeResult.setResultCallback(mUpdatePlaceDetailsCallback);
    }
};

private ResultCallback <PlaceBuffer> mUpdatePlaceDetailsCallback=new ResultCallback<PlaceBuffer>() {
    @Override
    public void onResult(@NonNull PlaceBuffer places) {

        if(!places.getStatus().isSuccess()){
            places.release();
            return;
        }
        final Place place=places.get(0);

        try {
            mPlace= new PlaceInfo();
            mPlace.setIsim(place.getName().toString());
            mPlace.setAdres(place.getAddress().toString());
            mPlace.setCepNo(place.getPhoneNumber().toString());
            mPlace.setAttributions(place.getAttributions().toString());
            mPlace.setId(place.getId().toString());
            mPlace.setLatLng(place.getLatLng());
            mPlace.setRating(place.getRating());
            mPlace.setWebsiteUri(place.getWebsiteUri());

        } catch (NullPointerException e){
        }

        moveCamera(new LatLng(place.getViewport().getCenter().latitude,
                place.getViewport().getCenter().longitude),DEFAULT_ZOOM,mPlace.getIsim());

        places.release();


    }
};

自动完成功能正在运行,但是单击项目后没有任何反应。选择项目后,我想要选择的位置。你能帮助我吗?

0 个答案:

没有答案