【发布时间】:2020-01-06 16:41:26
【问题描述】:
如果有人可以帮助我,我真的很合适。
我将我的第二个 RecyclerView 与自定义滑动按钮对象一起应用,这里 fun handleSwipeClick 设置为处理该操作。
我的问题是:如何使这个函数 (handleSwipeClick) 专门处理每一行? Like 删除此行项目
适配器 #1
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = baxters[position]
holder.listItem_time.text = item.intakeTime
holder.itemView.dose_recycler_view.apply {
dose_recycler_view.setHasFixedSize(true)
layoutManager = LinearLayoutManager(context)
dose_recycler_view.layoutManager = layoutManager
//Swipe action
val swipe = object: SwipeHelper(context,dose_recycler_view, 400){
override fun instaniateSwipeButton(
viewHolder: RecyclerView.ViewHolder,
buffer: MutableList<SwipeButton>
) {
// Adding Buttons
buffer.add(
SwipeButton(context,
"",
30,
R.drawable.ic_check_circle,
Color.parseColor("#66ff66"),
object : ButtonClickListener {
override fun handleSwipeClick(id: Int) {
// Click action
// TODO call to change LAST TAKEN and NEW INTAKE
Companion.errorToast(
context,
"Medicijn ingenomen. $id"
)
}
})
)
}
}
adapter = ClientDoseListAdapter(item.doses.toMutableList())
setRecycledViewPool(viewPool)
}
}
适配器 #2
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = doses[position]
/// DELETE THIS ROW
holder.med_name.text = item.medicineItem.name
holder.dose_amount.text = item.amount.toString()
}
【问题讨论】:
标签: kotlin android-recyclerview