Android AutocompleteTextView using ArrayAdapter and Filter

醉酒当歌 提交于 2019-11-30 05:58:52

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.

Mohsin Naeem

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();
}

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;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!