Я использую SectionedRecyclerViewAdapter из luizgrp / SectionedRecyclerViewAdapter в качестве адаптера для моего RecyclerView. Но отображается только первый заголовок. Контент не отображается и второй заголовок не отображается. Любая подсказка о том, что я делаю не так?
Мой RoundSection.kt выглядит следующим образом
class RoundSection(private val title: String, private val items: List<Pair<RoundExercise, Exercise>>, sectionParameters: SectionParameters) : Section(sectionParameters) {
override fun getContentItemsTotal(): Int = items.size
override fun getItemViewHolder(view: View): RecyclerView.ViewHolder = ItemViewHolder(view)
override fun onBindItemViewHolder(holder: RecyclerView.ViewHolder?, position: Int) {
val itemViewHolder = holder as ItemViewHolder
itemViewHolder.exerciseName.text = items[position].second.name
}
override fun getHeaderViewHolder(view: View): RecyclerView.ViewHolder = HeaderViewHolder(view)
override fun onBindHeaderViewHolder(holder: RecyclerView.ViewHolder) {
val headerViewHolder = holder as HeaderViewHolder
headerViewHolder.roundHeader.text = title
}
internal class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val exerciseName: TextView = itemView.exerciseName
}
internal class HeaderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val roundHeader: TextView = itemView.roundHeader
}
}
Мой фрагмент_работы_детали. xml выглядит следующим образом
class WorkoutDetailsFragment : Fragment(R.layout.fragment_workout_details) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val sectionParameters = SectionParameters.builder()
.itemResourceId(R.layout.round_exercise_item)
.headerResourceId(R.layout.round_header)
.build()
val sectionAdapter = SectionedRecyclerViewAdapter()
roundRecyclerView.layoutManager = LinearLayoutManager(context)
roundRecyclerView.adapter = sectionAdapter
val exercise = Exercise("exercise name", "exercise desc", 0, 1)
val roundExercise = RoundExercise(0, 1, 5, 0, 0, 0)
sectionAdapter.addSection(RoundSection("Round 1", listOf(roundExercise to exercise), sectionParameters))
val exercise1 = Exercise("exercise name1", "exercise desc1", 0, 2)
val roundExercise1 = RoundExercise(0, 2, 5, 0, 0, 0)
sectionAdapter.addSection(RoundSection("Round 2", listOf(roundExercise1 to exercise1), sectionParameters))
}
}
Мой фрагмент_работы_детали. xml выглядит следующим образом
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".ui.WorkoutDetailsFragment">
<TextView
android:id="@+id/workoutName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/workout_name_workout_details_fragment"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<TextView
android:id="@+id/workoutDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/workout_description_workout_details_fragment"
app:layout_constraintTop_toBottomOf="@+id/workoutName" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/roundRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/workoutDescription" />
</androidx.constraintlayout.widget.ConstraintLayout>
Мой round_header. xml выглядит следующим образом
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
<TextView
android:id="@+id/roundHeader"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:text="Row Header Name"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
</RelativeLayout>
Мой round_exercise_item. xml выглядит следующим образом
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
<TextView
android:id="@+id/exerciseName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:text="Exercise Name"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
</RelativeLayout>