I'm trying to use the expandable section in my project but I have an issue to close a section. When I click on an arrow nothing happens. So, I think I'm doing the exact behaviour as the sample do. It's my code:
The section
class LessonMenuSection(private val titleSection: String,
private val sectionAdapter: SectionedRecyclerViewAdapter)
: StatelessSection(SectionParameters.builder()
.itemResourceId(R.layout.lesson_menu_item)
.headerResourceId(R.layout.lesson_menu_head)
.build()) {
var expanded = true
override fun getContentItemsTotal() = if (expanded) 1 else 0
override fun getItemViewHolder(view: View) = LessonMenuHolder(view)
override fun getHeaderViewHolder(view: View) = HeadHolder(view)
override fun onBindItemViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val lessonHolder = holder as LessonMenuHolder
lessonHolder.bind(titleSection)
}
override fun onBindHeaderViewHolder(holder: RecyclerView.ViewHolder) {
val subHeaderHolder = holder as HeadHolder
subHeaderHolder.bind(titleSection, sectionAdapter)
}
class HeadHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private var expanded = true
fun bind(titleSection: String, sectionAdapter: SectionedRecyclerViewAdapter) {
itemView.subheaderText.text = titleSection
itemView.rootView.setOnClickListener {
expanded = !expanded
val imgID: Int = if (expanded) R.drawable.ic_keyboard_arrow_down_black
else R.drawable.ic_keyboard_arrow_up_black
itemView.arrow.setImageResource(imgID)
sectionAdapter.notifyDataSetChanged()
}
}
}
class LessonMenuHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(titleSection: String, clickListener: (LessonMenuHolder) -> Unit) {
itemView.categoryName.text = "vai logo"
itemView.setOnClickListener { clickListener(this) }
}
}
}
I'm not familiar with Kotlin. But, I notice you have 2 different variable scopes. Both of them named expanded. I guess you don't want to deal with the expanded within HeadHolder scope.
Hi guys,
I'm trying to use the expandable section in my project but I have an issue to close a section. When I click on an arrow nothing happens. So, I think I'm doing the exact behaviour as the sample do. It's my code:
The section
The way that I'm instantiating it.
Just one more information. I'm using Conductor instead of Fragment.