Error using notifyDataSetChanged in android array adapter

前端 未结 2 391

11-06 19:52:25.958: E/AndroidRuntime(29609): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notifi

2条回答
  •  -上瘾入骨i
    2020-12-30 04:04

    Try this (just a guess):

    @Override
        public Filter getFilter() {
            Filter filter = new Filter() {
                @Override
                protected FilterResults performFiltering(CharSequence constraint) {
                    FilterResults filterResults = new FilterResults();
                    if (constraint != null) {
                        ArrayList list = autocomplete(constraint.toString());
                        if (list != null) {
                            filterResults.values = list;
                            filterResults.count = list.size();
                        }
                    }
                    return filterResults;
                }
    
                @Override
                protected void publishResults(CharSequence constraint, FilterResults results) {
                    if (results != null && results.count > 0) {
                        //change the underlying data immediately before notifying UI                        
                        resultList = (ArrayList)results.values; 
                        notifyDataSetChanged();
                    }
                    else {
                        notifyDataSetInvalidated();
                    }
                }};
            return filter;
        }
    

提交回复
热议问题