[英]Android Kotlin listview adapter filter shows only first item
我制作了一個自定義 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)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.