适配器recyclerview中的列表为空

时间:2020-01-09 20:46:36

标签: android kotlin searchview

我想在带有Room db的回收者视图列表中进行搜索。在mhetod setAll中,我在列表的arraylist中设置了此值一次设置的一些值(我调试)

    internal fun setAll(productEntity: List<ProductEntity>) {
        this.filterListResult = productEntity
        lists.addAll(filterListResult)
        notifyDataSetChanged()

搜索后此列表为空

 override fun getFilter(): Filter {
        return object : Filter() {
            override fun performFiltering(constraint: CharSequence?): FilterResults {

                val charSearch = constraint.toString()
                if (charSearch.isEmpty())
                    filterListResult = productsList
                else {
                    val resultList= ArrayList<ProductEntity>()

                    lists.size
                    for (row in lists){
                        if(row.productName.toLowerCase().contains(charSearch.toLowerCase()))
                            resultList.add(row)
                    }

                    filterListResult = resultList

0 个答案:

没有答案