Split a single column list on multiple columns in recyclerView

I want to display a large list of words on a recycler view. Taking advantage of the screen width as compared to the column width, I thought it was a good idea to spread the list on say four columns while keeping the vertical scrolling capability. For this I found this very useful kotlin method chunked :

fun <T> Iterable<T>.chunked(size: Int): List<List<T>>(source)

So in my function setInfoBase() I get a list of entities Mot from a room database query, which I map in a list of String (Mot.mot) that I chunk (size 4) before sending it as the list of data to my adapter:

private var queryResult : List<List<String>> = listOf(listOf())
private fun setInfoBase() {
    val viewModel = ViewModelProvider(requireActivity())[SharedViewModel::class.java]
    viewModel.getMotsFiltres().observe(viewLifecycleOwner) { mots ->
        mots?.let {
            binding.totalBase.text = mots.count().toString()
            binding.totalActifs.text = mots.filter { it.baseActive }.count().toString()
            queryResult = mots.map {it.mot}.chunked(4)
            println(queryResult)
            adapter.setList(queryResult)
            adapter.notifyDataSetChanged()
        }
    }
}

This works like charm.

Then I have an adapter with a list item made of one row of four TextViews (row_mot1...row_mot4) I intent to populate with each line of the chunked queryResult

Here is the simple_list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/row_mot1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/row_mot2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/row_mot3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/row_mot4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />
</LinearLayout>

The issue is in the adapter, in the override fun onBindViewHolder it seems the lines of the list are truncated to two elements instead of four. The IDE seems to know that, as there is a warning that the line count cannot exceed 2 (why 2?). But I could not find where the issue comes from.

Here is the code of the adapter :

package com.simonwintz.millemots

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class SimpleAdapter (private val motItemLayout: Int) : RecyclerView.Adapter<SimpleAdapter.ViewHolder>() {
    private var motList : List<List<String>>? = null

    override fun onBindViewHolder(holder: ViewHolder, listPosition: Int) {
        val rowmot1 = holder.rowmot1
        val rowmot2 = holder.rowmot2
        val rowmot3 = holder.rowmot3
        val rowmot4 = holder.rowmot4

        motList?.let {
            val ligne = motList!![listPosition]
            println(ligne)
            val count = ligne.count()
            rowmot1.text = ligne[0]
            if (count > 1) {
                rowmot2.text = ligne[1]
            } else if (count > 2) {
                rowmot3.text = ligne[2]
            } else if (count > 3) {
                rowmot4.text = ligne[3]
            }
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(motItemLayout, parent, false)
        return ViewHolder(view)
    }

    fun setList(mots: List<List<String>>) {
        motList = mots
        println(motList)
        notifyDataSetChanged()
    }

    override fun getItemCount(): Int {
        return if (motList == null) 0 else motList!!.size
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var rowmot1: TextView = itemView.findViewById(R.id.row_mot1)
        var rowmot2: TextView = itemView.findViewById(R.id.row_mot2)
        var rowmot3: TextView = itemView.findViewById(R.id.row_mot3)
        var rowmot4: TextView = itemView.findViewById(R.id.row_mot4)
    }
}

And here the adapter initialization routine:

private var queryResult : List<List<String>> = listOf(listOf())
private lateinit var adapter : SimpleAdapter
private fun setAdapter() {
    val recyclerView = binding.listeMots
    adapter = SimpleAdapter(R.layout.simple_list_item)
    recyclerView.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
    recyclerView.adapter = adapter
}

I printed the truncated list queryResult on the logcat at all possible stages and it looks very normal. But I still cannot get rid of the warning and at running the list appears truncated indeed.

Has someone an idea what I am doing wrong ? Thanks for your help !

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật