Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm retrieving a list of strings from a webservice and I want to list them up on a AutoCompleteTextField regardless of the built-in AutoCompleteTextField filters.

How do I do that? is there a way to disable it's inner filtering easily (preferably without subclassing) I've loaded all my results into a ArrayAdapter, the problem is that some of them don't show up because of the filtering.

If I'm going in the wrong direction please point me to the right direction.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
561 views
Welcome To Ask or Share your Answers For Others

1 Answer

Probably @Alon meant subclassing ArrayAdapter, instead of AutoCompleteTextView. In getFilter() method one has to return a custom filter, that performs no filtering at all (in its performFiltering()). Probably the performance could be a problem - because theread is spawned. The best thing would be to derive from TextEdit and implement own completion popup. But this is again too many hassle for me, so far. Finally, I did something as follows and it works for me. Any feedback appreciated.

public class KArrayAdapter<T> 
extends ArrayAdapter<T>
{
    private Filter filter = new KNoFilter();
    public List<T> items;

    @Override
    public Filter getFilter() {
        return filter;
    }

    public KArrayAdapter(Context context, int textViewResourceId,
            List<T> objects) {
        super(context, textViewResourceId, objects);
        Log.v("Krzys", "Adapter created " + filter);
        items = objects;
    }

    private class KNoFilter extends Filter {

        @Override
        protected FilterResults performFiltering(CharSequence arg0) {
            FilterResults result = new FilterResults();
                result.values = items;
                result.count = items.size(); 
            return result;
        }

        @Override
        protected void publishResults(CharSequence arg0, FilterResults arg1) {
            notifyDataSetChanged();
        }
    }
}

Hope it helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...