如何在Groupie Android中更新HeaderItem

时间:2020-04-14 10:39:31

标签: android kotlin android-recyclerview

我有这样的HeaderItem

class HeaderItem(private val groupName: String,private val groupEditListener: GroupEditListener) : Item() {
    override fun bind(viewHolder: GroupieViewHolder, position: Int) {
        viewHolder.apply {
            itemView.tvGroupName.text = "Group : $groupName"
        }

        viewHolder.itemView.tvEdit.setOnClickListener {
            groupEditListener.onEditClicked(this@HeaderItem,groupName)
        }
    }

    override fun getLayout(): Int {
        return R.layout.group_single_item
    }


}

我有一个这样的ChildItem

class ChildItem(private val childNamee:String): Item() {
    override fun bind(viewHolder: GroupieViewHolder, position: Int) {
        viewHolder.apply {
            itemView.tvName.text = childNamee

        }
    }

    override fun getLayout(): Int {
        return R.layout.entries_single_item
    }



}

然后我像这样设置GroupieAdapter

val groupAdapter = GroupAdapter<GroupieViewHolder>().apply {
            groups.forEach { group ->
                val section = Section()
                section.setHeader(HeaderItem(group.name.toString(),groupEditListener))
                section.addAll(group.entries?.map { it -> ChildItem(it.name.toString()) }!!)
                this.add(section)

            }
        }

        recyclerViewGroups.apply {
            layoutManager = linearLayoutManager
            adapter = groupAdapter
        }

现在我想更新HeaderItem,并得到像这样的更新数据

disposable = RxBus.listen(GroupNameBridge::class.java).subscribe {
        val updateHeader = HeaderItem(it.name,groupEditListener)
        //I am not sure how to update this particular item
        }

但是我不确定如何在GroupAdapter中更新此特定项目。任何帮助,将不胜感激。谢谢。

0 个答案:

没有答案