以下是我的代码
var items : MutableList<Any> = arrayListOf()
items.add(TeacherDetails(it?.photo,it?.firstName,it?.lastName,it?.level))
items.add(TeacherBio(it?.bio))
items.add(TitleAccreditations(getString(R.string.acreditations)))
items.add(SessionsTitle(it?.firstName + getString(R.string.apostrophe) + getString(
R.string.sessions)))
items.addAll(listOf(it?.classes ?: arrayListOf()))
items.add(IntroVideo(it?.introVideo))
items.addAll(it?.teachingAccreditations?.split("\n")?.map { Accreditation(
it
) }?: emptyList())
问题在下一行,它将整个列表添加为对象而不是单个项目。
items.addAll(listOf(it?.classes ?: arrayListOf()))
以下是我的模型
data class Teacher(
@field:SerializedName("firstName")
val firstName: String? = null,
@field:SerializedName("lastName")
val lastName: String? = null,
@field:SerializedName("teacherId")
val teacherId: String? = null,
@field:SerializedName("introVideo")
val introVideo: String? = null,
@field:SerializedName("level")
val level: String? = null,
@field:SerializedName("teachingAccreditations")
val teachingAccreditations: String? = null,
@field:SerializedName("classes")
val classes: List<ClassesItem?>? = null,
@field:SerializedName("photo")
val photo: String? = null,
@field:SerializedName("bio")
val bio: String? = null
)