我正在使用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)))
}
}
})
}
非常感谢。
答案 0 :(得分:2)
您似乎错过了使用Section.setHeader的机会。因此,您将需要为每个WorkoutItem("Workout ${(w.workoutId)}"
集合项创建一个标头实例w
,然后将此实例传递到ExpandableGroup
构造函数和Section.setHeader
答案 1 :(得分:1)
根据@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)
}
})
}