Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had the exact same problem. After examining the ArrayAdapter and AutoCompleteTextView source code, I found out that the problem was, in short, that:</p> <ul> <li>the original object list is stored in <code>ArrayAdapter.mObjects</code>.</li> <li>However, <code>AutoCompleteTextView</code> enables <code>ArrayAdapter</code>'s filtering, meaning that new objects are added to <code>ArrayAdapter.mOriginalValues</code>, while <code>mObjects</code> contains the filtered objects.</li> <li><code>ArrayAdapter.getCount()</code> always returns the size of <code>mObjects</code>.</li> </ul> <p>My solution was to override <code>ArrayAdapter.getFilter()</code> to return a non-filtering filter. This way <code>mOriginalValues</code> is <code>null</code> and <code>mObjects</code> is used instead in all cases.</p> <p>Sample code:</p> <pre><code>public class MyAdapter extends ArrayAdapter&lt;String&gt; { NoFilter noFilter; /* ... */ /** * Override ArrayAdapter.getFilter() to return our own filtering. */ public Filter getFilter() { if (noFilter == null) { noFilter = new NoFilter(); } return noFilter; } /** * Class which does not perform any filtering. * Filtering is already done by the web service when asking for the list, * so there is no need to do any more as well. * This way, ArrayAdapter.mOriginalValues is not used when calling e.g. * ArrayAdapter.add(), but instead ArrayAdapter.mObjects is updated directly * and methods like getCount() return the expected result. */ private class NoFilter extends Filter { protected FilterResults performFiltering(CharSequence prefix) { return new FilterResults(); } protected void publishResults(CharSequence constraint, FilterResults results) { // Do nothing } } } </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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