So I have recyclerview here, and I want to delete a specific element by clicking on that element's delete button (here, the trash icon is the image button). How do I do it?
1 Answer
You can make use of the interface to do that. Make a interface class like this:
interface OnItemClickListener {
fun onDeleteIconClick(position)
}
Add listener object in the Recyclerview Adapter constructor
class RecyclerAdapter(
val context: FragmentActivity,
val listner: OnItemClickListener
) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
}
Then, on delete icon click add below code
listner.onDeleteIconClick(position)
then, on fragment or activity implement the interface and do whatever you want on the implemented method
