How to inflate custom layout in details fragment leanback

842 views Asked by At

I need to inflate/add a full width custom layout after DetailOverviewRow but there is no way and you can only add a ListRow.

1

There are 1 answers

2
MohammadReza Eram On BEST ANSWER

I found my answer:

First i need to create a class that extends RowPresenter and inflate my view into that, also create a class that extends Row and put my data into that.

FullWidthPresenter:

class FullWidthPresenter : RowPresenter() {

    override fun createRowViewHolder(parent: ViewGroup): ViewHolder {
        return ViewHolder(
            LayoutInflater.from(parent.context).inflate(
                R.layout.fullwidth_row,
                parent,
                false
            )
        )
    }
}

And CustomRow:

class CustomRow(val item: String) : Row()

In use:

val selector = ClassPresenterSelector().apply {

        FullWidthRowPresenter().also {
           addClassPresenter(CustomRow::class.java, it)
        }
      
        val rowsAdapter = ArrayObjectAdapter(selector)

        val customRow = CustomRow("Media Item Details")
        rowsAdapter.add(customRow)
        adapter = rowsAdapter
}