Following is my code
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())
Issue is at following line it is adding entire list as object instead of individual item.
items.addAll(listOf(it?.classes ?: arrayListOf()))
Following is my model
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
)
I guess because your type
of list
is Any
, it will consider adding list
instance also as an object
, so instead it as listOf()
just add directly
items.addAll(it?.classes?.filterNotNull()?: arrayListOf())