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
In my Android project I have a complex RecyclerView. The structure of my RecyclerView looks like the attached image.
In a few words, I have a main RecyclerView which contains a CardView, within the CardView I have another RecyclerView and each element can expand and collapse.
I have tried using a nested RecyclerView implementation (which is easy to find in Google by typing "Nested RecyclerView"), but this implementation has a bottleneck. When I call onBindViewHolder it calls setAdapter method and causes a bug when I scroll the RecyclerView.
Could you please give me any tips on how to implement such RecyclerView? What is the best way of building such Recycler adapters?
Here is an image how it looks like
Here is what I found about my way of implementing RecyclerView
This can be easily done with Concat Adapter.
https://www.youtube.com/watch?v=n_mrrva_z
this is my Mockup app using Concat adapter.
Think of Concat Adpater as an arrayList. Its coded like ConcatAdapter(HeaderAdapter, Adapter2, HorizontalAdapter)
I have gone through other questions as well but couldn't figure out something. I have a well set up RecyclerView.
I m trying this library: https://github.com/AAkira/ExpandableLayout
Now I want the items to be expandable so that they show a TextView which is different for each item.
But I can't figure out how to place itms in XML. Where to place RecyclerView and where the expandable layout? How to setup these things?
Take a look at one of the samples given in the library, it is called 'examplerecyclerview' which I think is the one you need.
These are specific files that you should watch:
RecyclerView Activity and Adapter (Java)
RecyclerView Activity (XML)
RecyclerView List Row (XML)
My problem is simple: I need to make a layout similar to android.R.layout.simple_expandable_list_item_1 which can fit more than one textview in the layout, as well as show the little '>' symbol that indicates that the tab is expandable.
How can this best be accomplished? My first thought was to use the layout as a background of a linear layout with two textviews in it, but I can't seem to make that work.
Vogella has a pretty good tutorial on how to achieve custom list views through Adapters.
Basically, what you do is you create a Layout with the looks you want for the list items and then you extend an adapter (ArrayAdapter for instance), see section 4. Then, in your activity, you create an instance of your Adapter implementation and populate it from an Array containing the data for the list.
Also have a look at the Developers site for how to make the list scroll smoothly with the ViewHolder pattern.
And if you feel you need more info on the expandable part maybe the hive can help.
RecyclerView is added into v7 support library since Android API 22 officially. And many people said that it is a enhancement over ListView and many brief introductions to the usage of it were posted over the internet. But most of these articles are very simple, shallow and hollow. The enhancement is just RecyclerView.ViewHolder, RecyclerView.ItemAnimator or RecylerView.SmoothScroller? Did the recycling and reuse mechanism of items' views during scrolling differ from the ListView's? And what exactly is the enhancement of RecyclerView over ListView?
Any answers, tips or links are appreciated. Thanks in advance.
And what exactly is the enhancement of RecyclerView over ListView?
RecyclerView is not an "enhancement" "over ListView", strictly speaking. ListView actually does something; RecyclerView, on its own, does not. A more accurate comparison would be that the RecyclerView framework is an improvement over AdapterView, and to some extent the AbsListView parent class of ListView and GridView.
RecyclerView focuses on widget recycling and gross child View management. It delegates everything else to other classes. AdapterView does far less of this, making it more difficult to extend functionally.
Of note:
Laying out the children, within the scrollable space of the RecyclerView, is delegated to managers. Hence, not only do three ship with recyclerview-v7 (list, grid, staggered grid), but others can be developed for alternative scenarios (e.g., overlapping children, for a StackView or Gallery sort of experience).
Updates from adapters can be much more fine-grained. With AdapterView, you pretty much have to redraw the entire view (e.g., a ListView and all its rows) on any change of significance, especially when adding and removing items. The update mechanism in the RecyclerView adapters indicate the specific positions that change. Not only does this require less processing time, but it helps enable the animated effects that RecyclerView offers (again, with pluggable replacements) for adding, moving, and removing items.
Other stuff that was "baked into" ListView, like drawing dividers, is now pulled out into extension points, such as an ItemDecorator. Now, you can choose how to "decorate" items, with line dividers or boxes or colored bar separators or whatever. Decoration is not limited to "dividers", but can affect anything in the views that, for one reason or another, you consider to be separate from the item views themselves.
RecyclerView, though, is fairly complicated to get going. What you get from ListView "out of the box" takes a lot more code -- yours or a third-party library's -- to match. For experienced developers, this is a feature, in that the code is replaceable with other code. For newcomers, this is a bug, in that there is a steeper learning curve for RecyclerView, IMHO.
As per the official documentation RecyclerView is a major enhancement over ListView. It contains many new features like ViewHolder, ItemDecorator, LayoutManager, and SmoothScroller. But one thing that certainly gives it an edge over the ListView is; the ability to have animations while adding or removing an item.
View Holders
In ListView, defining view holders was a suggested approach for
keeping references for views. But it was not a compulsion. Although by
not doing so, ListView used show stale data. Another major drawback of
not using view holders could lead to a heavy operation of finding
views by ids every time. Which resulted in laggy ListViews.
This problem is solved in RecylerView by the use of
RecyclerView.ViewHolder class. This is one of the major differences in
RecyclerView and ListView. When implementing a RecyclerView this class
is used to define a ViewHolder object which is used by the adapter to
bind ViewHolder with a position. Another point to be noted here, is
that while implementing the adapter for RecyclerView, providing a
ViewHolder is compulsory. This makes the implementation a little
complex, but solves the issues faced in ListView.
Layout Manager
When speaking of ListViews, only one type of ListView is available
i.e. the vertical ListView. You cannot implement a ListView with
horizontal scroll. I know there are ways to implement a horizontal
scroll, but believe me it was not designed to work that way.
But now when we look at Android RecyclerView vs ListView, we have
support for horizontal collections as well. In-fact it supports
multiple types of lists. To support multiple types of lists it uses
RecyclerView.LayoutManager class. This is something new that ListView
does not have. RecyclerView supports three types of predefined Layout
Managers:
LinearLayoutManager – This is the most commonly used layout manager in
case of RecyclerView. Through this, we can create both horizontal and
vertical scroll lists. StaggeredGridLayoutManager – Through this
layout manager, we can create staggered lists. Just like the Pinterest
screen. GridLayoutManager– This layout manager can be used to display
grids, like any picture gallery.
Item Animator
Animations in a list is a whole new dimension, which has endless
possibilities. In a ListView, as such there are no special provisions
through which one can animate, addition or deletion of items. Instead
later on as android evolved ViewPropertyAnimator was suggested by
Google’s Chet Haase in this video tutorial for animations in ListView.
On the other hand comparing Android RecyclerView vs ListView, it has
RecyclerView.ItemAnimator class for handling animations. Through this
class custom animations can be defined for item addition, deletion and
move events. Also it provides a DefaultItemAnimator, in case you don’t
need any customizations.
Adapter
ListView adapters were simple to implement. They had a main method
getView where all the magic used to happen. Where the views were bound
to a position. Also they used to have an interesting method
registerDataSetObserver where one can set an observer right in the
adapter. This feature is also present in RecyclerView, but
RecyclerView.AdapterDataObserver class is used for it. But the point
in favor of ListView is that it supports three default implementations
of adapters:ArrayAdapter CursorAdapter SimpleCursorAdapter Whereas RecyclerView
adapter, has all the functionality that ListView adapters had except
the built in support for DB cursors and ArrayLists. In
RecyclerView.Adapter as of now we have to make a custom implementation
to supply data to the adapter. Just like a BaseAdapter does for
ListViews. Although if you wish to know more about RecyclerView
adapter implementation, please refer to Android RecyclerView Example.
Item Decoration
To display custom dividers in a ListView, one could have easily added
these parameters in the ListView XML:
android:divider="#android:color/transparent"
android:dividerHeight="5dp" The interesting part about Android
RecyclerView is that, as of now it does not show a divider between
items by default. Although the guys at Google must have left this out
for customization, intentionally. But this greatly increases the
effort for a developer. If you wish to add a divider between items,
you may need to do a custom implementation by using
RecyclerView.ItemDecoration class. Or you can apply a hack by using
this file from official samples: DividerItemDecoration.java
View Holders
RecylerView by the use of RecyclerView.ViewHolder class. This is one
of the major differences in RecyclerView and ListView. When
implementing a RecyclerView this class is used to define a ViewHolder
object which is used by the adapter to bind ViewHolder with a position
Layout Manager
support for horizontal collections as well. In-fact it supports
multiple types of lists. To support multiple types of lists it uses
RecyclerView.LayoutManager class. This is something new that ListView
does not have. RecyclerView supports three types of predefined Layout
Managers: LinearLayoutManager – This is the most commonly used layout
manager in case of RecyclerView. Through this, we can create both
horizontal and vertical scroll lists. StaggeredGridLayoutManager –
Through this layout manager, we can create staggered lists. Just like
the Pinterest screen. GridLayoutManager– This layout manager can be
used to display grids, like any picture gallery.
Item Animator
RecyclerView has RecyclerView.ItemAnimator class for handling
animations. Through this class custom animations can be defined for
item addition, deletion and move events. Also it provides a
DefaultItemAnimator, in case you don’t need any customizations.
Adapter
In RecyclerView.Adapter as of now we have to make a custom
implementation to supply data to the adapter. Just like a BaseAdapter
does for ListViews.
Source: http://www.truiton.com/2015/03/android-recyclerview-vs-listview-comparison/