Skip to content
Advertisement

Android RecyclerView addition & removal of items

I have a RecyclerView with an TextView text box and a cross button ImageView. I have a button outside of the recyclerview that makes the cross button ImageView visible / gone.

I’m looking to remove an item from the recylerview, when that items cross button ImageView is pressed.

My adapter:

JavaScript

My layout is:

JavaScript

How can I get something like an onClick working for my crossButton ImageView? Is there a better way? Maybe changing the whole item onclick into a remove the item? The recyclerview shows a list of locations that need to be edited. Any technical advice or comments / suggestions on best implementation would be hugely appreciated.

Advertisement

Answer

I have done something similar. In your MyAdapter:

JavaScript

Edit:

getPosition() is deprecated now, use getAdapterPosition() instead.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement