Android AutocompleteTextView using ArrayAdapter and Filter

后端 未结 3 1133
梦如初夏
梦如初夏 2020-12-29 22:04

Backgroud information

The app I am currently writing deals with places. The main method to create a place is to enter an address. Providing a convenient way to do

相关标签:
3条回答
  • 2020-12-29 22:36

    Try to change this part of the code:

    if ( filterResults.count > 0) {
        lastSuggested = (ArrayList<Address>) filterResults.values;
    }
    lastInput = constraint.toString();
    

    into this:

    if ( filterResults.count > 0) {
        lastSuggested = (ArrayList<Address>) filterResults.values;
        lastInput = constraint.toString();
    }
    
    0 讨论(0)
  • 2020-12-29 22:46

    I think your problem is you are setting lastSuggested to suggested (via filterResults.values) and then, in the next pass, you are updating suggested --> lastSuggested will be set to the same value as suggested as Java passes variables by reference unless primitives.

    So, instead of

    if ( filterResults.count > 0) { lastSuggested = (ArrayList) filterResults.values; }

    You should try

    if ( filterResults.count > 0) {
        lastSuggested.clear();
        ArrayList<Address> tempList = (ArrayList<Address>) filterResults.values;
        int i = 0;
        while (i < tempList.size()){
            lastSuggested.add(tempList.get(i));
            i += 1;
        }
    }
    
    0 讨论(0)
  • 2020-12-29 22:58

    The Geocoder api is not designed to give suggestions on partial strings like "10 rue Guy Ro" . You can try this in Google maps, enter "10 rue Guy Ro" and leave a space. You will not get any suggestions(Google maps is using Geocoder) but when you remove the space you will get suggestions on the partial string (Google Maps is using private API). You can use the Geocoder api the same way Google maps use, fetch the suggestion only after the user input space in the string he is typing.

    0 讨论(0)
提交回复
热议问题