Reputation: 1348
I am using Firebaseui's recyclerview to show values in cart which is a RecyclerView. I have delete button in each row of recyclerview and when i click on delete button it should delete value from Firebase's database and also row in recyclerview should get deleted. But problem is when i click anywhere on recyclerview both item and database value gets deleted.
Here is the onClick code i am using :
recyclerViewCart.addOnItemTouchListener(
new RecyclerItemClickListener(Cart.this, recyclerViewCart, new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View childView, int position) {
Log.v(TAG, "YouClickon" + position);
key = mRecyclerViewAdapter.getRef(position).getKey();
listRef.child(key).removeValue();
}
}) {
}
);
I want to perform this operation only when user clicks on delete button. How should i do this. Please help.
Upvotes: 1
Views: 447
Reputation: 598728
Your click handler is wired to the entire item, so it will indeed run whenever that item is clicked.
If you want to only delete the item when the user clicks the button, you should wire up the click handler to that button. You can do this in your populateViewHolder()
method:
public void populateViewHolder(ChatHolder chatMessageViewHolder, Chat chatMessage, int position) {
chatMessageViewHolder.getDeleteButton().setOnClickListener(...).
}
Upvotes: 1