Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just use on section but multi layout #5

Open
fjr619 opened this issue Jul 10, 2020 · 3 comments
Open

Just use on section but multi layout #5

fjr619 opened this issue Jul 10, 2020 · 3 comments

Comments

@fjr619
Copy link

fjr619 commented Jul 10, 2020

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

@skydoves
Copy link
Owner

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)
    }
}

@fjr619
Copy link
Author

fjr619 commented Jul 12, 2020

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
Copy link
Author

fjr619 commented Jul 12, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants