AutoCompleteTextView does not work when giving space


I have a TextAutoCompleteView, which brings the data from a WebServices and when loading the adapter to make the suggestions, everything works perfectly.

The problem I have when including a space, since it eliminates all possibilities.

Example if I put San Juan

Only take the value "San" when giving space to lose all suggestions

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,listaCargada1);
asked by AndreyC1995 16.02.2018 в 16:49

1 answer


To work with spaces you must modify the Adapter, in this case create a CustomAdapter.

I add a example (created by Alex Melnykov ).

    public class BookAutoCompleteAdapter extends BaseAdapter implements Filterable {

    private static final int MAX_RESULTS = 10;
    private Context mContext;
    private List<Book> resultList = new ArrayList<Book>();

    public BookAutoCompleteAdapter(Context context) {
        mContext = context;

    public int getCount() {
        return resultList.size();

    public Book getItem(int index) {
        return resultList.get(index);

    public long getItemId(int position) {
        return position;

    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) mContext
            convertView = inflater.inflate(R.layout.simple_dropdown_item_2line, parent, false);
        ((TextView) convertView.findViewById(;
        ((TextView) convertView.findViewById(;
        return convertView;

    public Filter getFilter() {
        Filter filter = new Filter() {
            protected FilterResults performFiltering(CharSequence constraint) {
                FilterResults filterResults = new FilterResults();
                if (constraint != null) {
                    List<Books> books = findBooks(mContext, constraint.toString());

                    // Assign the data to the FilterResults
                    filterResults.values = books;
                    filterResults.count = books.size();
                return filterResults;

            protected void publishResults(CharSequence constraint, FilterResults results) {
                if (results != null && results.count > 0) {
                    resultList = (List<Books>) results.values;
                } else {
        return filter;

     * Returns a search result for the given book title.
    private List<Book> findBooks(Context context, String bookTitle) {
        // GoogleBooksProtocol is a wrapper for the Google Books API
        GoogleBooksProtocol protocol = new GoogleBooksProtocol(context, MAX_RESULTS);
        return protocol.findBooks(bookTitle);
answered by 16.02.2018 / 18:46