I'm trying to figure out how to get access to the views in my recyclerView. I want to be able to expand items in the recyclerView. When one expands, all the others should collapse.
class CustomAdapter(private val mList: List<Card>) : RecyclerView.Adapter<CustomAdapter.ViewHolder>() {
class ViewHolder(ItemView: View) : RecyclerView.ViewHolder(ItemView) {
val textView: TextView = itemView.findViewById(R.id.questionView)
val categoryView: TextView = itemView.findViewById(R.id.category_view)
val solutionView: TextView = itemView.findViewById(R.id.solutionView)
val editButton: FloatingActionButton = itemView.findViewById(R.id.floatingActionButton)
}
// create new views
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.items_view_design, parent, false)
return ViewHolder(view)
}
// binds the list items to a view
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val itemsViewModel = mList[position]
holder.textView.text = itemsViewModel.question
holder.categoryView.text = itemsViewModel.subjectCategory
holder.solutionView.text = itemsViewModel.solution
fun showHide(view:View) {
view.visibility = if (view.visibility == View.VISIBLE){
View.GONE
} else{
View.VISIBLE
}
}
fun show(view:View){
view.visibility =View.VISIBLE
}
fun hide(view:View){
view.visibility = View.GONE
}
holder.textView.setOnClickListener{
showHide(holder.solutionView)
showHide(holder.editButton)
}
//This is where I need help.
}'''
In pseudocode, what I want to say is:
- for loop (items in mList)
- items.solution = holder.solutionView
- hide(solutionView)
But I can't figure out how to get access to holder.categoryView for an item that isn't the current item being bound.