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.
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
Related
I have a recyclerView and list of items. Items are observed in viewModel, adapter gets a changed list whenever list in viewModel changes.
However, I have a problem when updating certain item views in existing list item - these changes happen, but to see them I have to scroll up or down a bit. In view holder I have all necessary if/else cases what to update according to item values. Is there a way to update item view instantly, without having to scroll?
You can call adapter.notifyDataSetChanged() function to force the adapter to redraw all items again.
you should use adapter.notifyItemChanged(int indexOfChangedItem) or adapter.notifyDataSetChanged() after you changing any item of the list.
the first one will update 'all' item viewes but the second one will update only the view that you passed it's index.
I am using recycler view(https://github.com/thoughtbot/expandable-recycler-view) to display list of sections and subsections. It is working just fine. But when I am trying to update the list with live data and using :- recyclerView.adapter = adapter by creating adapter everytime when live data updates. But when data is updated, it collapses the each section regardless it was expanded already. I want to keep state of list as it was when updating it. Can someone tell me how to achieve this or any other way of updating the adapter that keep the state of list same(if it is expanded, remain expanded, collapsed, remain same). Thanks in advance.
So, I have a recyclerview with multiple view types. I'm using this link to generate my adapter class, becauseI have multiple viewholders in my recyclerview. Now the problem I have is with collapsing certain items inside it. What I want is whenever I press
the green toggle, item 2 and 3 in the list should collpase but 4,5,6 should remain upon,unless you have clicked on the green item ofcourse. I tried many ways to approach this but I can not achieve this with the link provided. Is there any way I can achieve this?
When you click collapsing button you have to remove your collapsing data from your all source list. When you remove your item from your list recyclerView automatically animates it.After that when you want to show it again you have to insert it your list again and notify that.RecyclerView also animates again when you insert it. There is a useful link here for inserting and removing special data from recyclerView https://medium.com/#suragch/updating-data-in-an-android-recyclerview-842e56adbfd8
Generally, I plan to use SwipeRefreshLayout and RecyclerView to implement Pull-To-Refresh list. After pulling the list to refresh the data, it seems that the original item position has been added one for refreshing widget. Since it is the position of the item that decides what kind of views should be drew or loaded, after refreshing, it was detected that the position of the same item was increased by 1, which directly leads to the IndexOutOfBoundException when I try to access the last item in the original list.
Is there any method that I can handle this position change so that the last item will be available without any exception?
I have vertical RecyclerView for scrolling group of items and horizontal RecyclerView in each ViewHolder in order to scrol items inside of these groups. They are populated from database. Whenever item content is changed (user tap something or new data come from network) it is written to database and then notifyDataSetChanged() is called for the group cursor. I check if it is the same group in onBingViewHolder() and update items only if it is. But horizontal RecyclerView is scrolled anyway to the first item.
How could I prevent this behavior and why does it happens ?
BTW I'm writing result of this check in 'onBindViewHolder()` to the log and I can see that it is the same item.
Thanks.
RecyclerView creates new ViewHolder in order to perform animation. setItemAnimator(null) solved my problem.