Disable view recycling when using ConcatAdapter - android

I have a RecyclerView which has a header and a list of data below the header. I have two adapters for these two and are merged using ConcatAdapter. I want the header to be not recycled and I tried setting setIsRecyclable to false for the ViewHolder in the first adapter. However, it seems not to work and is always recycled. This is predictable because ConcatAdapter is also a child of the RecyclerView adapter. Is there any way that I can stop recycling a particular viewholder in a particular adapter while using ConcatAdapter?

Related

Multiple LayoutManager in ConcatAdapter

I want to implement an ConcatAdapter like this image:
This page's recyclerView contains these elements:
Title
Horizontal recyclerView (with pagination)
Title
Vertical recyclerView (no pagination)
Title
Horizontal recyclerView (with pagination)
But the problem is I can set only one LayoutManager to recyclerView that holds ConcatAdapter as I know.
How can set different layoutmanager to each adapter?
Or any other solution to implement this page with CocantAdapter?
(Why ConcatAdapter? Because it sovle performance prblems of nestedRecyclerView even with recyclerViewPool as I know)
This unfortunately is not possible. A RecyclerView adapter is just a component to provide and bind views for each row. A ConcatAdapter is no different, it just redirects from the individual adapters.
If it did have any control over the layout managers it would really defeat the entire point of the modularity of RecyclerView, which is what makes it so powerful in the first place.
You can take a look at the source code here to find out more about how it is implemented.
Simple solution is to create a Viewpool in the Activity/Fragment.
The Adapter for the recyclerview has 2 different types of items,
The regular one and the other that actually has a recyclerview with the horizontal layout as Adapter in it.
So a Viewholder that holds a recyclerview inside with its own viewholders.
Then you just grab the created viewpool from the activity to assign it as the shared Pool to all of the adapters with the horizontal scroll, thats it :-)
Concat Adapter doesnt help with this im afraid so this would be my alternative solution

Android - Recyclerview lagging with webview inside viewholder

I have a recyclerview which populates different types of ViewHolders based on the data provided in the adapter arraylist. In one of the scenarios I have to populate a viewholder that shows HTML text inside a webview. When this viewholder is added, the recyclerview lags while scrolling. If this viewholder is removed then the recyclerview scrolls fine.
Other viewholders need to be update-able since they change UI based on user interactions, and some viewholders add additional objects into the recyclerview when user clicks on the viewholder(expandable recyclerview item). So the position of the viewholders might not be same on every occation.
Is there a way to fix this scrolling issue. Or atleast to pre-load that one particular viewholder and keep it unchanged?

Why recyclerview is faster than listview [duplicate]

This question already has answers here:
Android Recyclerview vs ListView with Viewholder
(7 answers)
Closed 3 years ago.
I was reading about the difference b/w recyclerview and listview and found out that recyclerview is faster than listview.
I tried to search online but not found any satisfactory answer I know it is used ViewHolder pattern and Notifying adapter but what does it does intearlly so it is faster?
Recycler View you could say is an efficient way to create list of views.
If you have 1000 items like ur contact list , and If ur visible screen can show only 10 items at once, it will Create only 10+1 (or +2) Views and as u scroll , items/views that left will be reused (not create) to show new data.
Recycler View by default does this, where as List View by default doesn't do.
There are some differences between these two views.
ListView is a bit heavy and it has a lot of responsibilities. Whenever we have to handle the list, such as to configure it in some way, the only way to do this is through the ListView object or inside the adapter.
A lot of bad things in the ListView were fixed or changed in the RecyclerView. It’s more efficient by default, the layout is separated and we have more possibilities over the data set inside the adapter.
These are some crucial differences between ListView and RecyclerView:
1 ViewHolder
The ViewHolder pattern allows us to make our list scrolling act smoothly. It stores list row views references and, thanks to this, calling the findViewById() method only occurs a couple of times, rather than for the entire dataset and on each bind view.
The RecyclerView’s adapter forces us to use the ViewHolder pattern. The creating part (inflating the layout and finding views) and updating the views is split into two methods — onCreateViewHolder() and onBindViewHolder().
The ListView, on the other hand, doesn’t give us that kind of protection by default, so without implementing the ViewHolder pattern inside the getView() method, we’ll end with inefficient scrolling in our list.
2 LayoutManager
The LayoutManager takes responsibility for layouting row views. Thanks to this, RecyclerView doesn’t have to think about how to position the row view. This class gives us the opportunity to choose the way that we want to show the row views and how to scroll the list. For example, if we want to scroll our list vertically or horizontally, we can choose LinearLayoutManager. For grids, it is more suitable to choose the GridLayoutManager.
Previously, with the use of the ListView, we were only able to create a vertical-scrolling list, so it wasn’t that flexible. If we wanted grids on our list, we had to choose the other widget for that — GridView.
3 ItemDecoration
A duty of the ItemDecoration is simple in theory – add some decorations for the list row views – but in practice, it’s that simple to implement if we want to create a custom one. In this case, we should extend the ItemDecoration class and implement our solution. For example, the RecyclerView list has no dividers between rows by default and it’s consistent with the Material Design guidelines. However, if we want to add a divider for some reason, we can use DividerItemDecoration and add it to the RecyclerView. In case we use the ListView, we have to figure out rows decorations by ourselves. There is no helper class like ItemDecoration for this widget.
4 ItemAnimator
The last but not least component of RecyclerView that I want to mention is ItemAnimator. As we can expect, it’s handling row views animations like list appearance and disappearance, adding or removing particular views and so on. By default, RecyclerView’s list animations are nice and smooth. Of course, we can change that by creating our own ItemAnimator, which is also not that easy. To make it easier, we should extend the SimpleItemAnimator class and implement the methods that we need (just add animations to a ViewHolder’s views). To be honest, implementing animations on the ListView was a pain. Again, we had to figure out how we want to handle them.
5 Notifying adapter
We have a couple of cool notifiers on the RecyclerView’s adapter. We are still able to use notifyDataSetChanged() but there are also ones for particular list elements, like notifyItemInserted(), notifyItemRemoved() or even notifyItemChanged() and more. We should use the most appropriate ones for what is actually happening, so the proper animations will fire correctly.
Using ListView, we were able to use just notifyDataSetChanged() on the adapter and then had to handle the rest ourselves, again.
Because of ViewHolder Pattern.
Thats was the simplest answer. Now for some details.
What recycler view does is what it's name indicates "Recycle", yes it recycles items, and it does it with the help of ViewHolder Pattern.
By Using ViewHolder we do-not need to call findViewByID() every time we go through getView()method. The reference for all rows are stored in-memory. This increases the performance significantly, as findViewByID()is a heavy process.
Hope this clears your confusion.

Using multiple RecyclerView's adapters

Is it possible when we have more than one recycler view adapter in one project?
Each adapter is assigned to 1 activity
You can bind one adapter to one RecyclerView and even change it later. It doesn't matter how many RecyclerView's and adapters you have.

What are the responsibilities of, and differences between, a RecyclerView Adapter and RecyclerView LayoutManager?

I am trying to understand the RecyclerView but I can't understand the difference between the Adapter and LayoutManager.
Can anyone explain it to me?
The adapter is used to create (and bind data to) views that correspond to each item in your dataset.
The layout manager is responsible for the layout of these views.
The adapter doesn't know how the views will be positioned and sized. This means you can swap the layout manager without having to change your adapter code e.g. switching from a LinearLayoutManager to GridLayoutManager.
Check out this answer for a deeper (though still high-level) explanation (scroll past the initial code block to the section about RecyclerView philosophy):
ListView to RecyclerView Migration for CustomView
So in Recycler View you need an Adapter to manage the data which will contain the Recycler view. Adapter will take the data it can come from internet or from internal database, than adapter fetches the dat when it gets the data without an error it comes back to adapter(e.g.adapter grabs data from dataset) then it shows the data in the View Holder in your card like a one cell in the Recycler View, View Holder is a class that manages the view and than that view appears in the Recycler View. The above image which i tried to draw shows that process for Horizontal Recycler
In my case i found these benifits when i working on them
Basically an Adapter is used to gather all corresponding data what you provided
to all views defined by you
after gathering all data it wants a layout to display thease views for this layoutmanager gives a flatform to show them .

Categories

Resources