Groupie Recycler查看添加到同一可扩展项目的所有项目

问题描述 投票:2回答:2

我正在使用Groupie库显示可扩展项,而我的问题是,与其通过父级可扩展标头下方的api调用检索到的项不同,它们都一起显示在列表的最后一项下。

我想要这个:

  • 标题1
    • 子标题1
    • 子标题1
    • 子标题1
  • 标题2
    • 子标题2
    • 子标题2

我有这个:

  • 标题1
  • 标题2
    • 子标题1
    • 子标题1
    • 子标题1
    • 子标题2
    • 子标题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)))
            }
        }

    })
}

非常感谢。

android android-recyclerview expandablelistview recycler-adapter
2个回答
2
投票

似乎您错过了使用Section.setHeader。因此,您需要为每个WorkoutItem("Workout ${(w.workoutId)}"集合项创建一个标头实例w,然后将该实例传递给ExpandableGroup构造函数和Section.setHeader


2
投票

基于此问题的解决方法,是@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)
        }
    })
}
© www.soinside.com 2019 - 2024. All rights reserved.