如何使用Groupie RecyclerView删除项目

时间:2020-09-01 01:18:59

标签: android kotlin android-recyclerview groupie

我正在使用Groupie填充我的RecyclerView,并且试图在我的RecyclerView中使用删除按钮才能正常工作。我想出了如何使用setOnItemClickListener在活动中执行此操作,但我希望仅在单击删除按钮时才调用侦听器:

val adapter = GroupAdapter<ViewHolder>()
...
recycleview_my_cards.adapter = adapter
...

        //this works
        adapter.setOnItemClickListener { item, view ->
            val userCardItem = item as UserCardItem
            val id = userCardItem.userCreditcard.id
            if (id != null) {
                deleteCard(id)
            }
            startActivity(intent)
            finish()
        }

        findViewById<Button>(R.id.deleteCreditCard)?.setOnClickListener {
            //how should this be done?
        }

0 个答案:

没有答案