How to customize PlaceAutocomplete widget dialog design to list places

后端 未结 4 1163
刺人心
刺人心 2020-12-13 01:01

I need to show list of places in dropdown using google placeAutocomplete widgets. Here I\'m getting dialog to show places according to my query but

4条回答
  •  独厮守ぢ
    2020-12-13 01:18

    You just need to create new arraylist every time in filter object

    @Override 
    public Filter getFilter() {
        Filter filter = new Filter() {
            @Override 
            protected FilterResults performFiltering(CharSequence constraint) {
                FilterResults results = new FilterResults();
                // Skip the autocomplete query if no constraints are given. 
                if (constraint != null) {
                    // Query the autocomplete API for the (constraint) search string. 
    
                   /**You just need to create new object then crash problem 
                     will not occur**/
                    mResultList = new ArrayList<>;
    
                    mResultList = getAutocomplete(constraint);
                    if (mResultList != null) {
                        // The API successfully returned results. 
                        results.values = mResultList;
                        results.count = mResultList.size();
                    } 
                } 
                return results;
            } 
    
            @Override 
            protected void publishResults(CharSequence constraint, FilterResults results) {
                if (results != null && results.count > 0) {
                    // The API returned at least one result, update the data. 
                    notifyDataSetChanged(); 
                } else { 
                    // The API did not return any results, invalidate the data set. 
                    //notifyDataSetInvalidated(); 
                } 
            } 
        }; 
        return filter;
    } 
    

提交回复
热议问题