How can I make sticky headers in RecyclerView? (with or without external lib)
You don't need to use any third party libraries. You can make use of ExpandableListView
without actually making it "expand and collapse" to do the exact same thing which you need. See my answer for this post. The advantage here is that you can deal with this as easily as you deal with an ExpandableListView
, with no custom code. You only need to add one line to what is otherwise a standard ExpandableListView
adapter.
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
...
((ExpandableListView) parent).expandGroup(groupPosition);
...
}
Your section headers, you can set as a group view and the list items as children. Your data structure need to be updated before being passed on to the adapter. It need to be a grouped data, not a plain list which you have to pass to the expandable adapter(for example an array of classes, each instance that contain a String
property for group header and an ArrayList
of IncomeExpense
objects). And when you update the data, make the update in the corresponding group, instead of the entire data.
Android sticky header RecyclerView/ Section Header RecyclerView
Since the previous answers don't provide a reliable solution, I propose my FlexibleAdapter library for RecyclerView, that is able to handle all following functionalities at once:
- Sticky functionality for headers with Sections, works with all 3 LayoutManagers and with ViewPager too.
- Selection Modes.
- Multiple item types with auto-mapping.
- Predefined ViewHolders.
- Expandable items with Selection Coherence.
- Draggable and Swipe-To-Dismiss.
- Animated Async Filter with spannable text.
- Scrolling Animations.
- EndlessScroll with Adapter binding.
- UndoHelper & ActionMode Helper.
- FastScroller.
- ...and more.
The idea behind is to avoid to create from scratch over again a custom Adapter for every project and to have more functionalities in one library, instead of relying on different libraries that support only 1 or 3 of them and that you cannot merge.
Related Topics
How to Install Android Sdk Build Tools on the Command Line
How to Size an Android View Based on Its Parent's Dimensions
How to Save State During Orientation Change in Android If the State Is Made of My Classes
Execution Failed for Task 'App:Mergedebugresources' Crunching Cruncher....Png Failed
How to Create a Transparent Demo Screen for an Android App
Textwatcher for More Than One Edittext
How to Use Accelerometer to Measure Distance for Android Application Development
Android: Disabling Highlight on Listview Click
Android Lollipop, Appcompat Actionbar Custom View Doesn't Take Up Whole Screen Width
How to Get the Correct Orientation of the Image Selected from the Default Image Gallery
How to Display Progress Dialog Before Starting an Activity in Android
How to Create a Popup Window (Popupwindow) in Android
Error - Android Resource Linking Failed (Aapt2 27.0.3 Daemon #0)