Search code examples
androidkotlinandroid-recyclerviewexpandablelistviewgroupie

Groupie RecyclerView All Items Added To The Same Expandable Item


I'm using the Groupie library for showing expandable items and my issue is that instead of the items retrieved through an api call being shown under each of their parent expandable header, they're all shown together under the last item on the list.

I would like to have this:

  • Header 1
    • Child header 1
    • Child header 1
    • Child header 1
  • Header 2
    • Child header 2
    • Child header 2

I have this instead:

  • Header 1
  • header 2
    • Child header 1
    • Child header 1
    • Child header 1
    • Child header 2
    • Child header 2

This is my code

 private fun updateUICurrentExercise(getCurrentWorkoutExercise: GetCurrentWorkoutExercise?) {

    adapter = GroupAdapter()
    val workouts = getCurrentWorkoutExercise?.workouts

    for (w in workouts!!) {

        exp = ExpandableGroup(WorkoutItem("Workout ${(w.workoutId)}"), false)
        getExercisesByWorkoutAPI(w.workoutId.toString())

        adapter.add(exp)
    }

    rvWorkout.adapter = adapter
}

 private fun getExercisesByWorkoutAPI(workoutId: String) {

    GetExercisesByWorkoutAPI.postData(jo, object : GetExercisesByWorkoutAPI.ThisCallback {
        override fun onSuccess(getExercisesByWorkout: GetExercisesByWorkout?) {
           
            for (e in getExercisesByWorkout?.exercises!!) {

                exp.add(Section(ExerciseItem(workoutId)))
            }
        }

    })
}

Solution

  • It looks like you missed to use Section.setHeader. So you will need to create one header instance WorkoutItem("Workout ${(w.workoutId)}" for each w collection item and then pass this instance into ExpandableGroup constructor and Section.setHeader