Groupie Recycler查看添加到同一可扩展项目的所有项目
Groupie RecyclerView All Items Added To The Same Expandable Item
我正在使用 Groupie 库来显示可扩展项目,我的问题是通过 api 调用检索的项目没有显示在每个 parent 可扩展项目下 header, 它们一起显示在列表的最后一项下。
我想要这个:
- Header 1
- Child header 1
- Child header 1
- Child header 1
- Header 2
- Child header 2
- Child header 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
collection 项目创建一个 header 实例 WorkoutItem("Workout ${(w.workoutId)}"
,然后将此实例传递给 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)
}
})
}
我正在使用 Groupie 库来显示可扩展项目,我的问题是通过 api 调用检索的项目没有显示在每个 parent 可扩展项目下 header, 它们一起显示在列表的最后一项下。
我想要这个:
- Header 1
- Child header 1
- Child header 1
- Child header 1
- Header 2
- Child header 2
- Child header 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
collection 项目创建一个 header 实例 WorkoutItem("Workout ${(w.workoutId)}"
,然后将此实例传递给 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)
}
})
}