From 2ea323825b532d35ca26eff2564566744d46d54c Mon Sep 17 00:00:00 2001 From: Donghyeon-Kim <63500239+Donghyeon0915@users.noreply.github.com> Date: Mon, 10 Apr 2023 22:19:04 +0900 Subject: [PATCH] =?UTF-8?q?[Fix]=20:=20=EC=9D=98=EC=95=BD=ED=92=88=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20RecyclerView=20Inconsistency=20detected=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=88=98=EC=A0=95=20(#91)=20(#96)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../medicine/adapter/MedicineFilterAdapter.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/presentation/src/main/java/com/example/smiley/medicine/adapter/MedicineFilterAdapter.kt b/presentation/src/main/java/com/example/smiley/medicine/adapter/MedicineFilterAdapter.kt index 53065c7..9c1ccdf 100644 --- a/presentation/src/main/java/com/example/smiley/medicine/adapter/MedicineFilterAdapter.kt +++ b/presentation/src/main/java/com/example/smiley/medicine/adapter/MedicineFilterAdapter.kt @@ -28,8 +28,10 @@ class MedicineFilterAdapter( } private lateinit var itemClickListener: OnItemClickListener - private var filteredList : List = emptyList() - private val unFilteredList : List = medicineList.medicines + private var filteredList : ArrayList = arrayListOf() + private val unFilteredList : ArrayList = arrayListOf().apply { + addAll(medicineList.medicines) + } private var userInput:String = "" /** @@ -85,8 +87,7 @@ class MedicineFilterAdapter( return object : Filter() { override fun performFiltering(p0: CharSequence?): FilterResults { userInput = "$p0" - - filteredList = + val newFilteredList = if (userInput.isEmpty()) arrayListOf() else { val filteringList = ArrayList() @@ -96,6 +97,9 @@ class MedicineFilterAdapter( filteringList } + filteredList.clear() + filteredList.addAll(newFilteredList) + val filterResults = FilterResults() filterResults.values = filteredList @@ -104,7 +108,6 @@ class MedicineFilterAdapter( @SuppressLint("NotifyDataSetChanged") override fun publishResults(p0: CharSequence?, results: FilterResults?) { - filteredList = results?.values as List notifyDataSetChanged() } }