android - Android Kotlin listview 适配器过滤器仅显示第一项
问题描述
我制作了一个自定义 ArrayAdapter 来填充我的列表,并添加了 edittext 来过滤列表视图,但列表视图只过滤第一项。
XML:
<EditText
android:id="@+id/invoiceSearchFilter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search invoice"
android:padding="15sp"
android:background="@drawable/edit_text_border"/>
<ListView
android:id="@+id/listViewInvoiceSearchList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="60dp"
android:layout_marginBottom="50dp"/>
科特林:
var listView = findViewById<ListView>(R.id.listViewInvoiceSearchList)
var adapter = InvoiceSearchListAdapter(this,idList, titleList, descList)
var thefilter = findViewById<EditText>(R.id.invoiceSearchFilter)
listView.adapter = adapter
thefilter.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {
}
override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {
(listView.adapter as InvoiceSearchListAdapter).filter.filter(charSequence)
}
override fun afterTextChanged(editable: Editable) {
}
})
ListView 正确显示所有条目,但为什么我输入文本来过滤列表,它只过滤第一项。
解决方案
使用 foreach 过滤查询如下希望它也有助于toLowerCase(Locale.getDefault())
避免区分大小写:
charSequence.forEach { q ->
(listView.adapter as InvoiceSearchListAdapter).filter.filter(q)
}
推荐阅读
- python - 从 pandas df 中删除行
- php - 类别页面返回 recv() 失败(104:连接重置..) Magento 1.9 multistore + nginx | php7.1 每分钟
- php - php表单到电子邮件中的html表格
- javascript - 如何使用 react-pose 实现动画刻度线?
- ios - 如何获取密钥的值并完成我的委托
- .net - dot Net 应用程序与 Zoho Desk 之间的集成?
- keras - U-net最终层
- c++ - 格式化宏以使用单行 if 语句
- css - Visual Studio 警告:.less 文件中未声明的 mixin
- ruby-on-rails - Rails 与迁移的递归关联