我正在使用Groupie库显示可扩展项,而我的问题是,与其通过父级可扩展标头下方的api调用检索到的项不同,它们都一起显示在列表的最后一项下。
我想要这个:
我有这个:
这是我的代码
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。因此,您需要为每个WorkoutItem("Workout ${(w.workoutId)}"
集合项创建一个标头实例w
,然后将该实例传递给ExpandableGroup
构造函数和Section.setHeader
基于此问题的解决方法,是@valerii的回复:在同一api调用中同时启动了可扩展组及其项。
private fun updateUICurrentExercise(getCurrentWorkoutExercise: GetCurrentWorkoutExercise?) {
adapter = GroupAdapter()
val workouts = getCurrentWorkoutExercise?.workouts
for (w in workouts!!) {
getExercisesByWorkoutAPI(w.workoutId.toString())
}
rvWorkout.adapter = adapter
}
private fun getExercisesByWorkoutAPI(workoutId: String) {
GetExercisesByWorkoutAPI.postData(jo, object : GetExercisesByWorkoutAPI.ThisCallback {
override fun onSuccess(getExercisesByWorkout: GetExercisesByWorkout?) {
val expandableGroup = ExpandableGroup(WorkoutItem("Workout $workoutId"), false)
for (e in getExercisesByWorkout?.exercises!!) {
expandableGroup.add(Section(ExerciseItem(e.exerciseName)))
}
adapter.add(expandableGroup)
}
})
}