0

I am using Firestore Paging Adapter for loading a list of data and displaying it in RecyclerView. I set onClickListener on each item loaded and I would like to remove item from RecyclerView if it is pressed. How can I do that. I get pressed item with

val pressedUserRealtion = getItem(adapterPosition)?.toObject(UserRelation::class.java)

and I would like to delete this item from my RecyclerView. I searched and couldn't find any method that would do that, I can't get the reference to list that contains loaded items. The only thing I can think of is setting the view visibility to GONE when user selects the item.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Alen
  • 949
  • 3
  • 17
  • 37
  • Do you want to remove the item from the database *and* the UI? Or only from the UI? – Frank van Puffelen Aug 16 '19 at 17:53
  • Well I do remove it from the database by executing cloud function which removes that document and also does other work. I know that there is FirestoreRecyclerAdapter which updates the recyclerView if new data is added, removed, changed but I would like to use FirestorePagingAdapter. Per documentation: "FirestoreRecyclerAdapter — binds a Query to a RecyclerView and responds to all real-time events included items being added, removed, moved, or changed. Best used with small result sets since all RESULTS ARE LOADED AT ONCE.". I have hundreds of rows of data so I want to use FirestorePagingAdapter – Alen Aug 17 '19 at 08:56
  • You say "Well I do remove it from the database by executing cloud function" so isn't also removed from the UI? – Alex Mamo Aug 17 '19 at 13:35
  • @AlexMamo I think the paging adapters in FirebaseUI don't auto-update, do they? If they don't, it'd need a page refresh. – Frank van Puffelen Aug 17 '19 at 13:58
  • @FrankvanPuffelen Oh yes, you're right, I missed that. Actually I answered a similar [question](https://stackoverflow.com/a/51175970/5246885) a year ago :) Btw, I'm looking forward to meed you in Madrid. – Alex Mamo Aug 17 '19 at 14:03

1 Answers1

0

for realtime update, you can use FirestoreRecyclerAdapter

FirestoreRecyclerAdapter — binds a Query to a RecyclerView and responds to all real-time events included items being added, removed, moved, or changed. Best used with small result sets since all results are loaded at once

Documentation

Jetwiz
  • 642
  • 7
  • 14