I started the debugger and my breakpoints show that on the first startup the dataset is being transmitted as the adapter is being initialized, but as soon as I call the filter it doesn't have any data to work with and my recyclerview just stays as it was before.
All this code worked before, I just translated it from Java to Kotlin. I must have messed something up, but I can't find it.
Adapter Class
class ClothingListAdapterKt(
private val dataSetIn: MutableList<Clothing>,
private val listener: ClothingListAdapterKt.OnItemClickListener,
private val context: Context
) :
RecyclerView.Adapter<ClothingListAdapterKt.ViewHolder>(), Filterable {
private var lastPosition = -1
var dataSet = mutableListOf<Clothing>()
var dataSetFiltered = mutableListOf<Clothing>()
init {
dataSet = dataSetIn
dataSetFiltered = dataSet
}
override fun onBindViewHolder(viewHolder: ClothingListAdapterKt.ViewHolder, position: Int) {
val currentClothing: Clothing = dataSetFiltered[position]
// Get element from your dataset at this position and replace the
// contents of the view with that element
//SETTING MY VIEWS, ONLY COMMENTED OUT FOR THIS QUESTION
}
setAnimation(viewHolder.itemView, position);
}
override fun getFilter(): Filter {
return object : Filter() {
override fun performFiltering(constraint: CharSequence?): FilterResults? {
val charString: String = constraint.toString()
if (charString.isEmpty()) {
dataSetFiltered.addAll(dataSet)
} else {
val dataSetTemp: MutableList<Clothing> = mutableListOf()
for (row in dataSet) {
if (row.name.lowercase().contains(charString.lowercase())) {
dataSetTemp.add(row)
}
}
dataSetFiltered = dataSetTemp
}
val filterResults = FilterResults()
filterResults.values = dataSetFiltered
return filterResults
}
override fun publishResults(constraint: CharSequence?, results: FilterResults?) {
dataSetFiltered = results?.values as MutableList<Clothing>
notifyDataSetChanged()
}
}
}
Adapter Init
recylcerViewClothing.adapter = ClothingListAdapterKt(clothing, listener, this.requireContext())
This is how I call the filter
adapter.filter.filter(searchTerm) //searchTerm is a String passed by the constructor of the function it sits in
this is my filter and It works properly