0

Image of my RecyclerView activity

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 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.