android过滤产品数量和查看更新

时间:2016-05-26 05:27:17

标签: android android-arrayadapter

我在适配器中使用listView.setOnItemClickListener打开弹出窗口来更新产品数量,当用户按下OK和QTY> 0然后调用活动中的监听器。这种方式模型和视图已正确更新。但是当我使用FilterResults过滤产品然后更新产品数量它显示数量,接下来我从动作栏搜索中搜索相同的产品我得到产品数量0。

这是我的代码

private class ItemFilter extends Filter {
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            FilterResults results = new FilterResults();
            if(constraint == null || constraint.length() == 0){
                results.values = originalData;
                results.count = originalData.size();

            }else{
                constraint = constraint.toString().toLowerCase();
                final List<Product> list = originalData;
                int count = list.size();
                final ArrayList<Product> filterlist = new ArrayList<Product>(count);

                for (Product product:list) {
                    String productCode          =  product.getProductCode();
                    String productName          =  product.getProductName() ;
                   // String genericName            =  product.getGenericName() ;
                    String packSize             =  product.getPackSize() ;
                    String unitTp               =  product.getUnitTp();
                    String unitVat              =  product.getUnitVat();
                    String updQty               =  product.getQty() != null ? product.getQty() : "0";

                    Product model = new Product(productCode, productName, null, packSize, unitTp, unitVat, updQty, null,null)  ;

                    if (productName.toLowerCase().startsWith(constraint.toString())) {
                        filterlist.add(model);
                    }
                }
                results.values = filterlist;
                results.count = filterlist.size();
            }
            return results;
        }

        @SuppressWarnings("unchecked")
        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            filteredData = (ArrayList<Product>) results.values;
            OrderDetailsAdapter.this.notifyDataSetChanged();
        }
    }

0 个答案:

没有答案