嗨,我正在开发一个应用程序,我已经在fregement中实现了recycler视图和searchview,我第一次根据文本的变化得到过滤产品。
但是当我一个接一个地删除文本时,所有的列表都将是空的。没有东西可以显示在最后。
这是我的密码

最佳答案

您正在名为array的单个plistarray上继续操作
filter()方法中,您清除了plistarray并再次使用相同的方法查找记录。所以您应该为适配器使用其他数组,而不是plistarray

public void filter(String text) {
        if (text.isEmpty()) {
            plistarray.clear();
            plistarray.addAll(plistarray);
        } else {
            ArrayList<ProductList> result = new ArrayList<>();
            text = text.toLowerCase();
            //after clearing the array again you are using same array to find the items from
            for (ProductList item : plistarray) {
                if (item.getPtitle().toLowerCase().contains(text)) {
                    result.add(item);
                }
            }
             //you have cleared all the contains here
            plistarray.clear();
            // and added only result related items here
            plistarray.addAll(result);
        }
        notifyDataSetChanged();
    }

07-28 12:33