Recycler view in a recycler view - android

I am looking for solution that solves a problem of a dynamic list that in turn contains a dynamic list of rows.
I have a recycler view which holds a card view that eventually holds another recyclerview. I can see that the parent recycler view is showing up but the child recycler is not showing up.
{{recyclerView{cardView{recyclerView}}}
The getItemCount method is being called but all the other methods such as onCreateViewHolder and bind are not being called.
I have made sure both the recycler views have the linearlayoutmanager implemented and have setFixedSize as true.

I believe it is the issue with your xml layout. Maybe it is not coming in focus hence it is not calling those overridden methods,as recylerview becomes unavailable.Make sure that the padding,height and rest other things are such that the child recyclerview is visible.Actually when I implemented it, I faced the same issue and the reason was my xml layout with the same reason as my second recyler was not visible due to overpadding and margin.

Found the problem. Had to upgrade to a newer version of recycler view. And added wrap content. It started working.

Related

Impelement two recyclerview in one screen

How can I implement this kind of UI, where we have two recyclerViews. One scrolls horizontally and the second one vertically. when the second one scrolls first one also scrolls top together.
I tried to implement using NestedScrollView, but I had to make second recyclerView height wrap content which causes recyclerView not recycle.
The second way that I tried was having one recyclerView. And adding horizontal recyclerview as a header. The problem was to save header recyclerview scroll state when navigation. And there had been crashes when loading next page (paging 3) in header recyclerView.
The question is: Is there any optimal solution for this kind of ui?
In cases, Like this, you don't have to use 2 RecyclerView and you also have to avoid using RecyclerView insideScrollView. instead of this you have to use one vertical RecyclerView with multitype view Adapter.
in this way, you are going to have 2 different ViewHolder one of them is a horizontal recyclerView (your top item) and the other one is your other items.
for learning multitype adapter you can see this:
How to create RecyclerView with multiple view types
and for a horizontal recyclerView inside a vertical RecyclerView you can see this :
https://medium.com/#ashishkudale/android-list-inside-list-using-recyclerview-73cff2c4ea95
you have to combine these 2.
I could not understand the meaning of "header" where you said "adding horizontal recyclerview as a header" but if you did what I told and the problem is the state of inner Horizontal recyclerView, I think probably you are calling setAdapter method of horizontal RecyclerView in OnBind() method of your vertical recycler view, it is a common mistake that I have seen in many tutorials.
if you have done this mistake , try to call setAdapter of your inner recyclerView in the constructor of its viewHolder and just update the list using yourHorizontalAdapter.notifyDataSetChanged() in onBind() method of VerticalRecylerView,
and if its not the case and your recyclerView is completely destroying see this link :How to save RecyclerView's scroll position using RecyclerView.State?

How to make row list using recyclerView and card? Can I use Nested RecyclerView?

I'm trying to design a row list using RecyclerView like Android TV ↳ android.support.v17.leanback.widget.ListRow. I'm able to design list with title but not row list. Can anyone help me?
Please Follow this Link for
Recycer view like play store
Use Two RecyclerView Outer Recycler is vertical and Second horizontal recycler is item of first recycler View
All you need is to call mInnerRecycler.setNestedScrollingEnabled(false); on your inner RecyclerViews and use Horizontal scrollview as root of mInnerRecyclerView
Explanation:
RecyclerView has support for nested scrolling introduced in API 21 through implementing the NestedScrollingChild interface. This is a valuable feature when you have a scrolling view inside another one that scrolls in the same direction and you want to scroll the inner View only when focused.
In any case, RecyclerView by default calls RecyclerView.setNestedScrollingEnabled(true); on itself when initializing. Now, back to the problem, since both of your RecyclerViews are within the same ViewPager that has the AppBarBehavior, the CoordinateLayout has to decide which scroll to respond to when you scroll from your inner RecyclerView; when your inner RecyclerView's nested scrolling is enabled, it gets the scrolling focus and the CoordinateLayout will choose to respond to its scrolling over the outer RecyclerView's scrolling. The thing is that, since your inner RecyclerViews don't scroll vertically, there is no vertical scroll change (from the CoordinateLayout's point of view), and if there is no change, the AppBarLayout doesn't change either.
In your case, because your inner RecyclerViews are scrolling in a different direction, you can disable it, thus causing the CoordinateLayout to disregard its scrolling and respond to the outer RecyclerView's scrolling.
Notice:
The xml attribute android:nestedScrollingEnabled="boolean" is not intended for use with the RecyclerView, and an attempt to use android:nestedScrollingEnabled="false" will result in a java.lang.NullPointerException so, at least for now, you will have to do it in code.
RecyclerView can check View Type for return header or item. And use layout manager for manage how to item scrolling direction.
RecyclerView (vertical scrolling)
- item -> RecyclerView (horizontal scrolling) check view type is header or item with condition example : is object has type header
Ref : Google play store like interface using recycler view

Android RecyclerView scrolls to top when child element is expanded/collapsed

I have a list of elements in a recycler view that are generated dynamically using data binding. Each element has a bottom view that is initially set to View.GONE, however once a user clicks the element and the view is expanded, the recycler view automatically scrolls back to the top of the list. Conversely, if the view is expanded and then clicked again to collapse, the recycler view scrolls to the top of the list again. I have tried keeping track of the ID's of the elements for the adapter (again using data binding), setting focus to the child element when they expand or collapse, and using binding adapters to animate the expand/collapse itself.
My suspicion is that the adapter in the recycler view is receiving a onNotifyDataChanged() alert when the height of one of the child changes, rendering an additional view (still inside one of the children though, not a separate child in the list), and automatically scrolls to the top. Is there a way to override this? Does anyone know what else might be causing the list to snap to the top when one of the elements is clicked -> expanded/collapsed?
So I found the solution to my issue in case someone encounters something similar. I actually ended up finding this answer: RecyclerView notifyDataSetChanged scrolls to top position
and the second solution involving the staggered layout manager was the route I went with, since I want to be able to wrap the content. My suspicions were correct that it had to do with the changing height of the elements in the recycler view. The expandable item's parent wrapped content, so the recycler view was forced to recalculate the size of the item once the expandable portion appeared/disappeared (at least that's what I got out of it).

Content lost in RecyclerView after scrolling

I'm using RecyclerView to display a list of timeline, and each tweet of the timeline is shown as a CardView. But some contents of the cards are lost after the scrolling the RecyclerView down and scrolling back, as shown in the two screenshots below. The contents in the red rectangle is lost after scrolling.
BEFORE SCROLLING:
AFTER SCROLLING:
I'm wondering whether or not it's a bug of RecyclerView and find no solution after Googling for it.
By the way, I wrote a class extending Recycler.Adapter, which contains two methods onCreateViewHolder and onBindViewHolder. I put the ViewHolder's inflation work in the onBindViewHolder method. And I use a default LinearLayoutManager for the RecyclerView. I don't know if I should write a LayoutManager myself or not.

RecyclerView detaches view still visible

Current scenario
I'm using this library https://github.com/kanytu/android-parallax-recyclerview to achieve a parallax effect on a RecyclerView. So far, so good. However I would like get an effect like Google Newsstand where the header is still bellow the cards.
Problem
The problem is that RecyclerView (or LinerLayoutManager) detaches the header view the moment the first element of the list touches the top of the parent view:
As you can see the moment the first cardview touches the top is the moment RecyclerView detaches the header.
I'm sure that there is no problem on the logic itself I get RecyclerView.findViewHolderForPosition(0) == null when the card reaches the top. Proving that the header is recycled.
Tried Solutions
I tried many things like:
ViewHolder.setIsRecyclable using this method to set the holder to not recycler doesn't do any effect.
LayoutManager.ignoreView I tried marking the view to be ignored from being discarded and recycling. The result was an exception saying:
Trying to recycle an ignored view holder. You should first call stopIgnoringView(view) before calling recycle.
setItemViewCacheSize Doesn't do anything. Tried calling setItemViewCacheSize(50) and it doesn't do anything to the header.
setMaxRecycledViews Tried setting the max of recycled views with viewType=HEADER to 0 and it still recycles it.
Conclusion
So I question if there is anyway to mark the item for not getting detached until I order so (like checking if it's still visible and then detach it).
There is also an issue on the github about it: https://github.com/kanytu/android-parallax-recyclerview/issues/7
You can use the new design support library's CoordinatorLayout with your recyclerview and make the same effect with no issues like this.
check this link: http://android-developers.blogspot.com/2015/05/android-design-support-library.html

Categories

Resources