Skip to content

Commit

Permalink
[Fix] : 의약품 검색 RecyclerView Inconsistency detected 에러 수정 (#91) (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
dongx0915 authored Apr 10, 2023
1 parent 2c03f45 commit 2ea3238
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ class MedicineFilterAdapter(
}

private lateinit var itemClickListener: OnItemClickListener
private var filteredList : List<Medicine> = emptyList()
private val unFilteredList : List<Medicine> = medicineList.medicines
private var filteredList : ArrayList<Medicine> = arrayListOf()
private val unFilteredList : ArrayList<Medicine> = arrayListOf<Medicine>().apply {
addAll(medicineList.medicines)
}
private var userInput:String = ""

/**
Expand Down Expand Up @@ -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<Medicine>()
Expand All @@ -96,6 +97,9 @@ class MedicineFilterAdapter(
filteringList
}

filteredList.clear()
filteredList.addAll(newFilteredList)

val filterResults = FilterResults()
filterResults.values = filteredList

Expand All @@ -104,7 +108,6 @@ class MedicineFilterAdapter(

@SuppressLint("NotifyDataSetChanged")
override fun publishResults(p0: CharSequence?, results: FilterResults?) {
filteredList = results?.values as List<Medicine>
notifyDataSetChanged()
}
}
Expand Down

0 comments on commit 2ea3238

Please sign in to comment.