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() } }