我在 Fragments 中添加 Searchview 并且 Menuitem 已膨脹,但是當我單擊 Searchview 按鈕并輸入查詢時,Nothing Changes 并且我的資料未添加。請幫助
這是代碼答案應該在 Kotlin 中
覆寫 fun onQueryTextChange(p0: String?): Boolean {
temp.clear() //this is my temp array
var text=p0?.lowercase(Locale.getDefault())
if (text!!.isNotEmpty()){
makeText(activity as Context,"working",Toast.LENGTH_LONG).show()
value.forEach {
temp.add(it) //by this line data shoul add but not added
}
}else{
makeText(activity as Context,"no",Toast.LENGTH_LONG).show()
temp.clear()
temp.addAll(value)
recyclerView.adapter?.notifyDataSetChanged()
}
return true
}
})
uj5u.com熱心網友回復:
您應該檢查用戶的輸入文本是否為空,更新配接器的資料,然后呼叫 notifyDataSetChanged 來重繪 您的串列。
將您的第一個 if 范圍更改為:
if (text!!.isNotEmpty()) {
makeText(activity as Context, "working", Toast.LENGTH_LONG).show()
value.forEach {
temp.add(it) //by this line data shoul add but not added
}
recyclerView.adapter?.clear()
recyclerView.adapter?.addAll(temp)
recyclerView.adapter?.notifyDataSetChanged()
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/415018.html
標籤:
