Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid using AutoCompleteTextView with Location suggestions (Using Geocoder and getFromLocationName())
    primarykey
    data
    text
    <p>I have an AutoCompleteTextView where i want to search for locations, example: You type "vig" and the AutoCompleteTextView list shows the 5 best results for that: "4560 Vig", "Juan Pablo Perez..", "The Vig 4041...", "Vig" Another example, you type "vigo": it says the right place: "Vigo, Pontevedra" and you can select it and put it on the AutoCompleteTextView.</p> <p>For now, what i have is working almost good but i have one error:</p> <ol> <li>The display list is only showing when you delete on character, if not doesn't show, and what it shows is the last string result, example: you have typed "vigo", and nothing appears, you delete the "o" and the display list shows results for "vigo" instead of "vig", that is what is typed in the AutoCompleteTextView in the moment.</li> </ol> <hr> <p>I perform the search for the locations in an AsyncTask:</p> <pre><code>private class SearchAddress extends AsyncTask&lt;String, Void, String[]&gt; { @Override protected String[] doInBackground(String... params) { //adapter.clear(); String[] addressArray = getStreetList(query); return addressArray; } @Override protected void onPostExecute(String[] addressArray) { if(addressArray == null) Toast.makeText(NewRouteActivity.this, "No address obtained from server", Toast.LENGTH_SHORT).show(); else{ adapter.clear(); for(String address: addressArray){ adapter.add(address); &lt;------HERE IS THE 2ND ERROR Log.d("ASYNC", address); } } } @Override protected void onPreExecute() {} @Override protected void onProgressUpdate(Void... values) {} } </code></pre> <p>Here is my AutoCompleteTextView Code:</p> <pre><code>String[] array = {}; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_dropdown_item, array);//simple_dropdown_item_1line autoFrom.setAdapter(adapter); autoTo.setAdapter(adapter); asyncSearch = new SearchAddress(); autoFrom.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) {} @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (((AutoCompleteTextView) autoFrom).isPerformingCompletion()) {return;} if (s.length() &lt; 2) { return; }else{ query = s.toString(); if (asyncSearch.getStatus().equals(AsyncTask.Status.FINISHED)){ asyncSearch = new SearchAddress(); asyncSearch.execute(query); Log.d("ASYNC", "FINISH GOOD"); Log.d("ASYNC", query); }else{ Log.d("ASYNC", "CANCEL"); asyncSearch.cancel(false); asyncSearch = new SearchAddress(); asyncSearch.execute(query); } return; } } }); </code></pre> <p>I hope with this is enough, getStreetList() is working good, giving good results. If you need something else just ask.</p> <p>Thanks in advance!!! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload