Scrolling a page (fragment) with two RecyclerViews: State of the art & how about recycling?
This is precisely the use case for ConcatAdapter
as per the Concatenate adapters sequentially with ConcatAdapter blog post:
ConcatAdapter
is a new class available inrecyclerview:1.2.0-alpha02
which enables you to sequentially combine multiple adapters to be displayed in a singleRecyclerView
. This enables you to better encapsulate your adapters rather than having to combine many data sources into a single adapter, keeping them focused and re-usable.
This allows you to write your layout as a single RecyclerView
that correctly recycles views while keeping each individual adapter (and their loading of data) separate.
In your case, you should consider actually having 4 adapters - two simple ones for your titles (or two instances of the same TitleAdapter
you could write), plus one for each of your previous adapters.
Then you'd construct your ConcatAdapter
by passing all 4 adapters in to make one scrollable RecyclerView
:
val firstTitleAdapter = TitleAdapter("first title")
val firstListAdapter: FirstListAdapter = …
val secondTitleAdapter = TitleAdapter("second title")
val secondListAdapter: SecondListAdapter = …
val concatAdapter = ConcatAdapter(firstTitleAdapter, firstListAdapter,
secondTitleAdapter, secondListAdapter)
recyclerView.adapter = concatAdapter
Sync al horizontal RecyclerView inside vertical list view
Make an instance of RecyclerView.OnScrollListener
. This instance will be common to all your horizontal recycler views. When onScrolled( )
gets called, scroll all the views except the one on which this got called.
Related Topics
How to Change Style of a Default Edittext
Which Can Replace Capturepicture Function
Parse JSON Array Response Using Retrofit & Gson
Error:Connectionresult{Statuscode=Internal_Error, Resolution=Null}
Mapview Rendering with Tiles Missing with an "X" in the Center
Error: Failed to Resolve: Com.Android.Support:Appcompat-V7:29.0.1'
Certpathvalidatorexception:Trust Anchor for Certificate Path Not Found - Retrofit Android
Making a Https Request Using Android Volley
How to Get a Jacoco Coverage Report Using Android Gradle Plugin 0.10.0 or Higher
How to Import Eclipse Project to Android Studio
Open Specific Activity When Notification Clicked in Fcm
Listen to Own Application Uninstall Event on Android
How to Default to Numeric Keyboard on Edittext Without Forcing Numeric Input
How to Tell If the Soft-Keyboard Is Shown
How to Kill Sub Activities and Bring Activity to Top of Stack
Intent Does Not Set the Camera Parameters
Android -- How to Position View Off-Screen
Fitssystemwindows Effect Gone for Fragments Added via Fragmenttransaction