I have a RecyclerView with expandable list items. That means when the user clicks on an item it gets expanded and additional information is appearing. If the user is clicking again the item gets collapsed so that the additional information is hiding again.
My problem now is the following:
When i expand the first item and scroll down a bit and up again the first item is collapsed again automatically but the internal state ofcourse still is at the expanded state so i cant expand it anymore. Also when the first item is expanded and i scroll down some of the items are in the expanded state too without showing the additional data and i cant expand it anymore.
So that means i have to somehow disable the recycling mechanic. How can i do that?
I think disabling the recycling mechanic is the wrong solution. The whole idea of the recyclerview is to do this. What you need to do is to preserve the state
Related
I have a recycleview that I like to go past the last element when I scroll up. The reason I need to do this is that I have a floating button that if I don't go past the last item, the floating button covers the right part of the last item. I have seen this done in apps such as WhatsApp (see screenshot).
My approach has been to add two empty items to the end of my list and then set visibility of views based on if the items are empty or not. I feel this is more a hack and I was wondering if there is a better way around this.
Below is a screen shot from WhatsApp where at the end of the list, the list scrolls further.
Thanks in advance
There is not need to add two blank items to recyclerview. It may introduce bugs as well while adding new items to the recyclerview. You just need to provide paddingBottom to the recyclerview equal to the height of floating action button and set clipToPadding = false to the recyclerview.
I have a RecyclerView in bottom sheet. Every time I close and re-open the bottom sheet.
I would like the last RecyclerView scroll position to be ignored
(it should always display with item 0 as the top fully visible item as
if it was opened for the first time).
The data is always the same so I don’t need to reload it.
Is there a better option to accomplish this than scrollToPosition(0)?
you can achieve your purpose by calling
RecyclerView.smoothScrollToPosition(0);
or
RecyclerView.getLayoutManager().scrollToPosition(0) ;
or as you said
RecyclerView.scrollToPosition(0);
I am trying to implement a recycler view which will show items with rating and when ever rating changes it will flip the current rating with animation.
I am doing this on onBindView. The problem I am facing is, onBindView is called even view holder is partially visible ie. rating view is still not on screen and as a consequences it animate before its time.
Any help is appreciated. Thanks in advance.
You can listen for scroll events and determine which items have transitioned between non visible and fully visible.
Register a scroll callback with:
RecyclerView.addOnScrollListener
If you are using a LinearLayoutManager your callback can use the following methods to determine which items are visible:
LinearLayoutManager.findFirstVisibleItemPosition
LinearLayoutManager.findLastCompletelyVisibleItemPosition
It is up to you to track the changes in item state between non-visible and visible.
I have already read many question on SO and Google regarding Sticky headers in a recyclerview. However, most of them sticks the complete list item on top. I just want to stick part of my list item to top of recyclerview until the complete item is scrolled. I have gone through some libraries such as this one but still not able to figure out how to get it done. Any help is appreciated.
I want to stick the content which is highlighted in the red box until the complete list item (marked in green) is scrolled.
So you want to stick just a part of your list item link this?
Check out this library
https://github.com/oubowu/PinnedSectionItemDecoration
Combine with this RecyclerView Adapter library:
https://github.com/CymChad/BaseRecyclerViewAdapterHelper
I have a button in each item of a ListView whose background is defined by an XML, one background when enabled and another when disabled. When the ListView loads, it comes out correct. But, for some reason I can't figure out, if I scroll down and then scroll back up, the wrong background shows up.
I'd like to know the solution to this problem, but besides that, in general what I want to accomplish is this:
I have a button in the ListView to take the user to the website for the given item. If there is no website, I want the button to disappear, or be disabled. I seem to have the same problem with both options.
Thanks in advance for your efforts
It seems most likely that the problem lies with your getView() method. Android recycles views to save memory, so, for example, when you scroll down, it calls getView(int, View, ViewGroup) on your adapter where View is the item that just left the top of the screen. If you're not re-populating the item with the new data from the adapter, (ie, just returning convertView) it will put the View that left the top of the screen where the "new" one should be.