问题描述
我正在使用Groupie库显示可扩展项目,但我的问题是,与其通过父级可扩展标头下方的api调用检索到的项目不同,它们都一起显示在列表.
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.
我想要这个:
- 标题1
- 子标题1
- 子标题1
- 子标题1
- Header 1
- Child header 1
- Child header 1
- Child header 1
- 子标题2
- 子标题2
我有这个:
- 标题1
- 标题2
- 子标题1
- 子标题1
- 子标题1
- 子标题2
- 子标题2
- Header 1
- header 2
- Child header 1
- Child header 1
- Child header 1
- Child header 2
- Child header 2
这是我的代码
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))) } } }) }
推荐答案
您似乎错过了使用 Section.setHeader .因此,您将需要为每个
w
集合项创建一个标头实例WorkoutItem("Workout ${(w.workoutId)}"
,然后将该实例传递给ExpandableGroup
构造函数和Section.setHeader
It looks like you missed to use Section.setHeader. So you will need to create one header instance
WorkoutItem("Workout ${(w.workoutId)}"
for eachw
collection item and then pass this instance intoExpandableGroup
constructor andSection.setHeader
这篇关于Groupie Recycler查看添加到同一可扩展项目中的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!