I am using the spannedGridLayoutManager library in android Kotlin for recyclerview, but I am having problems. When I filter the list of items obtained from the recyclerview API it cannot be scrolled. Meanwhile, when I don't filter the list from the recyclerview API, it can be scrolled.
This is me code after filtering data in API
Class Adapter:
override fun onBindViewHolder(holder: DynamicMenuViewHolder, position: Int) {
with(holder){
with(listDynamicMenu[position]){
binding.descImg.text = this.titleEn
binding.img.load(Constant.IMAGES_URL+this.image)
binding.cardMenu.setOnClickListener { onMenuClick?.invoke(this) }
}
}
}
@SuppressLint("NotifyDataSetChanged")
fun add(newMenu: List<SubmenuItem?>?){
newMenu?.let {
//val filteredMenu = it.filterNot { it?.link == "hotel_guide" } // List<SubmenuItem?>
val filteredMenuNonNull = it.filterNotNull()
listDynamicMenu.apply {
clear()
addAll(filteredMenuNonNull)
notifyDataSetChanged()
}
}
}
Detail code adapter and fragment: Adapter
Class Fragment: Fragment