Firebase AutoCompleteTextView with CustomAdapter

0

I have a Custom Adapter in an AutoCompleteTextView that is pulling the data from Firebase, so far so good. The problem is that the suggestions are only filtered when I add the data manually like this:

 private ArrayList<CustomerTitle> populateCustomerData(ArrayList<CustomerTitle> customerTitle) {
        customerTitle.add(new CustomerTitle("Antonio", "Natanael", "123", "http://cdn.blog.psafe.com/blog/wp-content/uploads/2017/09/perfil-fake.jpg"));
        return customerTitle;
    }

So the suggestions appear normally, but when I pull with Firebase like this:

ValueEventListener AutoListTitle = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        customertitle.removeAll(customertitle);
        for (DataSnapshot single: dataSnapshot.getChildren()){
            CustomerTitle modelo = single.getValue(CustomerTitle.class);
            customertitle.add(modelo);
        }
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {

    }
};
mData2.child("ListaImgTitle").addValueEventListener(AutoListTitle);

Items are listed, but do not filter the suggestions. Example: When I type NA , only the start words for NA

Adapter:

public class CustomerAdapterTitle extends ArrayAdapter<CustomerTitle> {
    ArrayList<CustomerTitle> CustomerTitles, tempCustomerTitle, suggestions;
    Context context;
    private ImageLoader mImageLoader;
    public CustomerAdapterTitle(Context context, ArrayList<CustomerTitle> objects,ImageLoader MImageLoader) {
        super(context, android.R.layout.simple_list_item_1, objects);
        this.context = context;
        this.CustomerTitles = objects;
        this.tempCustomerTitle = new ArrayList<CustomerTitle>(objects);
        this.suggestions = new ArrayList<CustomerTitle>(objects);
        this.mImageLoader = MImageLoader;

    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CustomerTitle CustomerTitle = getItem(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.imagens_titulo, parent, false);
        }
        TextView txtCustomerTitle = (TextView) convertView.findViewById(R.id.tvCustomer);
        ImageView ivCustomerTitleImage = (ImageView) convertView.findViewById(R.id.ivCustomerImage);
        if (txtCustomerTitle != null)
            txtCustomerTitle.setText(CustomerTitle.getNomeImagen() + " " + CustomerTitle.getLastName());
        if (ivCustomerTitleImage != null && CustomerTitle.getImgTitle() != "")
            if(CustomerTitle.getImgTitle() != null)
                mImageLoader.displayImage(CustomerTitle.getImgTitle(),
                        ivCustomerTitleImage, null, new ImageLoadingListener() {
                            @Override
                            public void onLoadingStarted(String s, View view) {

                            }

                            @Override
                            public void onLoadingFailed(String s, View view, FailReason failReason) {

                            }

                            @Override
                            public void onLoadingComplete(String s, View view, Bitmap bitmap) {


                            }

                            @Override
                            public void onLoadingCancelled(String s, View view) {

                            }
                        }, new ImageLoadingProgressListener() {
                            @Override
                            public void onProgressUpdate(String s, View view, int i, int i1) {

                            }
                        });
        if (position % 2 == 0)
            convertView.setBackgroundColor(getContext().getColor(R.color.odd));
        else
            convertView.setBackgroundColor(getContext().getColor(R.color.even));

        return convertView;
    }


    @Override
    public Filter getFilter() {

        return myFilter;
    }

    Filter myFilter = new Filter() {
        @Override
        public CharSequence convertResultToString(Object resultValue) {
            CustomerTitle CustomerTitle = (CustomerTitle) resultValue;

            return CustomerTitle.getNomeImagen() + " " + CustomerTitle.getLastName();
        }

        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            if (constraint != null) {

                suggestions.clear();
                for (CustomerTitle people : tempCustomerTitle) {
                    Toast.makeText(context, "FilterResults", Toast.LENGTH_SHORT).show();
                    if (people.getNomeImagen().toLowerCase().startsWith(constraint.toString().toLowerCase())) {
                        suggestions.add(people);
                    }
                }

                FilterResults filterResults = new FilterResults();
                filterResults.values = suggestions;
                filterResults.count = suggestions.size();
                return filterResults;
            } else {
                return new FilterResults();
            }
        }

        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            ArrayList<CustomerTitle> c = (ArrayList<CustomerTitle>) results.values;
            if (results != null && results.count > 0) {
                clear();
                for (CustomerTitle cust : c) {
                    add(cust);
                    notifyDataSetChanged();
                }
            }
        }
    };
}
    
asked by anonymous 14.02.2018 / 02:30

0 answers