BaseRecyclerViewAdapter icon indicating copy to clipboard operation
BaseRecyclerViewAdapter copied to clipboard

Just use on section but multi layout

Open fjr619 opened this issue 5 years ago • 3 comments

How to make just use 1 section like in example, but with multi layout child. example if position is even then use view_even.xml, and if position is odd then use view_odd.xml ? thank you

fjr619 avatar Jul 10 '20 14:07 fjr619

Hi, @fjr619 You can implement it using the below example codes.

class SampleAdapter0(private val delegate: SampleViewHolder.Delegate) : BaseAdapter() {

    private val section_item = 0

    init {
        addSection(ArrayList<SampleItem>())
    }

    fun addItems(sampleItems: List<SampleItem>) {
        addItemsOnSection(section_item, sampleItems)
        notifyDataSetChanged()
    }

    override fun layout(sectionRow: SectionRow): Int {
        // if the sectionRow.row % 2 == 0, returns view_even.xml
       // else return view_odd.xml
    }

    override fun viewHolder(layout: Int, view: View): BaseViewHolder {
        return SampleViewHolder(view, delegate)
    }
}

skydoves avatar Jul 10 '20 14:07 skydoves

what is different between addSection addSectionList addItemOnSection addItemListOnSection, because the documentation still confusing. thank you

I tried :

    val section = mutableListOf<String>()
    section.add("test 1")
    section.add("test 2")
    section.add("test 3")
    addSection(section)

    for (index in 0 until sections().size){
      addItemListOnSection(index, sampleItems)
    }

but when i tried to log sections().size, the value is 1 why? should it be 3 right? example : i need make 3 section, each section have 5 item

fjr619 avatar Jul 12 '20 07:07 fjr619

Next question how to remove item? sorry for too much question, because this libs is good and want to maximize the usage in my project

fjr619 avatar Jul 12 '20 13:07 fjr619