I need to access a list that is in the Adapter, however, I need to access being in a ViewHolder, I know that with Java it would only refer to the list, but in Kotlin the list is not recognized,
class SearchFilterAdapter(private val filterList: List<Filter>) :
RecyclerView.Adapter<SearchFilterAdapter.ViewHolder>(), FastScrollRecyclerView.SectionedAdapter {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_search_filter, parent, false)
return ViewHolder(view)
}
override fun getItemCount(): Int {
return filterList.size
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(filterList[position])
}
override fun getSectionName(position: Int): String {
return filterList[position].group?.toUpperCase()!!
}
class ViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView) {
val sectionTextView = itemView?.sectionTextView
val filterCheckBox = itemView?.filterCheckBox
val rootLayout = itemView?.rootLayout
fun bind(filter: Filter) {
if(filter.isFirst) {
sectionTextView?.visibility = View.VISIBLE
sectionTextView?.text = filter.group?.toUpperCase()
} else {
sectionTextView?.visibility = View.GONE
}
filterCheckBox?.isChecked = filter.isChecked
filterCheckBox?.setOnCheckedChangeListener {
buttonView, isChecked ->
//filterList[position].isChecked = isChecked
}
filterCheckBox?.text = filter.category
}
}
}
Note that there is a comment, that is where I tried to access the list that is in the adapter.