codewaves / sticky-header-grid Goto Github PK
View Code? Open in Web Editor NEWSticky header grid layout manager for RecycleView
License: MIT License
Sticky header grid layout manager for RecycleView
License: MIT License
java.lang.ArrayIndexOutOfBoundsException: length=1; index=-1
at com.codewaves.stickyheadergrid.StickyHeaderGridLayoutManager.fillBottomRow(StickyHeaderGridLayoutManager.java:546)
at com.codewaves.stickyheadergrid.StickyHeaderGridLayoutManager.onLayoutChildren(StickyHeaderGridLayoutManager.java:406)
please take a look on new StickyHeaderGridLayoutManager(SPAN_SIZE);
Hi. My adapter good working anywhere but not working in dialog. RecyclerView is "empty" (but I see little gray line). itemsCount > 0
val dialog = MaterialDialog.Builder(activity)
.customView(R.layout.paid_sites_dialog, false)
.positiveText(R.string.done)
.negativeText(R.string.cancel)
.build()
val freeSitesTrigger = dialog.findViewById(R.id.freeSitesTrigger) as FreePaidTriggerButton
val sitesRecyclerView = dialog.findViewById(R.id.sitesRecycler) as RecyclerView
sitesRecyclerView.layoutManager = StickyHeaderGridLayoutManager(3)
sitesRecyclerView.adapter = FilterPaidSitesAdapter()
dialog.show()
Video: https://imgur.com/a/aF5b3nB
Tested sample app with the following data:
private static final int SPAN_SIZE = 3;
private static final int SECTIONS = 50;
private static final int SECTION_ITEMS = 200;
Is it possible to expand and collapse sections dynamically? I'd like to add click listeners to the headers that hide/show the items in it, but can't find a solution at the moment. Let me know if you need any more info. thanks!!
I have a RecyclerView with StickyHeaderGridLayoutManager and when using SwipeRefreshLayout the RecyclerView is not pulled down
Pleas Update to current SKD Version (27)
So I have a group with sub-items. When I remove the items it works fine with
notifySectionItemRemoved(section, item)
This removes the item, but if it's the last item, the header remains.
I have tried
notifySectionHeaderChanged(section);
and I have even tried using the initial RecyclerView adapter's
if (mGroupedList.get(section).postList.size() == 0) { notifyItemRemoved(section);}
Still no luck. Is there anything else I need to do to remove it?
In calculateSections method, the getSectionCount is called twice: the first time to populate mSections list and the second time to calculate mSectionIndices. This is working fine in case the whole work is done in one thread.
In my case, I had a big number of data to work on and I used several threads to do so and after finishing working on a section, I call the if the notifySectionDataSetChanged to be executed on the UI thread.
In some cases, if the work on the other threads is being processed faster than the UI thread, the values returned by getSectionCount between the first call and the second one, are different:
I/Sticky: section count before : 4
I/Sticky: section : StickyHeaderGridAdapter$Section@25ef8b0d
I/Sticky: section : StickyHeaderGridAdapter$Section@3c6a5ac2
I/Sticky: section : StickyHeaderGridAdapter$Section@14fbf0d3
I/Sticky: section : StickyHeaderGridAdapter$Section@8d80410
E/Sticky: section count after : 5
I fixed this by calling the getSectionCount only once.
Hi,
I have a performance issue especially API 19-20-21. I have a Viewpager and four horizontal recyclerview's which has different views inside my main recyclerview which has a adapter that extends StickyHeaderGridAdapter. While scrolling up and down if screen contains the sub recyclerviews or viewpager, frame drops.
Here is my implementation for recyclerviews. Is there any way to improves its performance. Because of the recyclers' views are different I can't use the same viewpool for them.
`final ViewHolderLowerRecyclerSlider lowerSlider = (ViewHolderLowerRecyclerSlider) viewHolder;
final LinearLayoutManager lowerSliderMan = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
lowerSlider.rvMainPageSlider.post(new Runnable() {
@OverRide
public void run() {
LowerCuffAdapter upperCuffAdapter = new LowerCuffAdapter(context, mData.get(section).getItems(), new MainPageAdapterClick() {
@OverRide
public void onItemClick(NewsItemsModel newsItem) {
clickListener.onItemClick(newsItem);
}
});
lowerSlider.rvMainPageSlider.setLayoutManager(lowerSliderMan);
lowerSlider.rvMainPageSlider.addItemDecoration(new CustomItemDecorationHorizontal(5, 10, 5, 10));
lowerSlider.rvMainPageSlider.setAdapter(upperCuffAdapter);
}
});
lowerSlider.rvFinance.post(new Runnable() {
@Override
public void run() {
FinanceAdapter financeAdapter = new FinanceAdapter(context, financeList);
LinearLayoutManager financeLayManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
lowerSlider.rvFinance.setLayoutManager(financeLayManager);
lowerSlider.rvFinance.setAdapter(financeAdapter);
}
});
lowerSlider.rvWeather.post(new Runnable() {
@Override
public void run() {
LinearLayoutManager weatherLayManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
WeatherAdapter weatherAdapter = new WeatherAdapter(context,list);
lowerSlider.rvWeather.setLayoutManager(weatherLayManager);
lowerSlider.rvWeather.setAdapter(weatherAdapter);
}
});`
Rationale: https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/
Quote (from a link above):
May 1st | Bintray, JCenter, GoCenter, and ChartCenter services will no longer be available
Note: it seems that Signal Android app depends on this (among many other projects).
@Codewaves let me know if I can help you with this.
I'm trying (and failing) to get this working with a PagedList for convenient paging of large datasets. Is this something you plan on introducing in the future?
I have implemented working fine but i am confuse here like simple recyclerview grdiview have SpacesItemDecoration to make spaces between two items how can i acheive this on this code pls help me here
Hi,
This library was working fine. But i cannot use equal space for grid items. Even if i add any other item decorator, it was affecting sticky header too. Is there is any solution?
currently header is not scrolled until whole section scrolled, I want to scroll header when user scroll not with section changed. How to do that ?
Is it possible to use library with staggered or obtain a staggered like view?
Fatal Exception: java.lang.NullPointerException
Attempt to read from field 'android.view.View androidx.recyclerview.widget.RecyclerView$d0.itemView' on a null object reference
at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:9)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:49)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:1)
at com.codewaves.stickyheadergrid.StickyHeaderGridLayoutManager.onLayoutChildren(StickyHeaderGridLayoutManager.java:31)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:38)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:37)
at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:5)
at android.view.View.layout(View.java:19712)
at android.view.ViewGroup.layout(ViewGroup.java:6113)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:19712)
at android.view.ViewGroup.layout(ViewGroup.java:6113)
at com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:6)
at com.google.android.material.appbar.ViewOffsetHelper.onViewLayout(ViewOffsetHelper.java)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:2)
at android.view.View.layout(View.java:19712)
at android.view.ViewGroup.layout(ViewGroup.java:6113)
at androidx.viewpager.widget.ViewPager.onLayout(ViewPager.java:258)
at android.view.View.layout(View.java:19712)
at android.view.ViewGroup.layout(ViewGroup.java:6113)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:19712)
at android.view.ViewGroup.layout(ViewGroup.java:6113)
at androidx.drawerlayout.widget.DrawerLayout.onLayout(DrawerLayout.java:56)
at android.view.View.layout(View.java:19712)
at android.view.ViewGroup.layout(ViewGroup.java:6113)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19712)
at android.view.ViewGroup.layout(ViewGroup.java:6113)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:19712)
at android.view.ViewGroup.layout(ViewGroup.java:6113)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19712)
at android.view.ViewGroup.layout(ViewGroup.java:6113)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:19712)
at android.view.ViewGroup.layout(ViewGroup.java:6113)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:789)
at android.view.View.layout(View.java:19712)
at android.view.ViewGroup.layout(ViewGroup.java:6113)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2516)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2237)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1411)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6784)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6719)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:449)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
This problem happened when I use header recycler on Xiaomi and Huawei devices.
Fatal Exception: java.lang.NullPointerException
Attempt to read from field 'android.view.View androidx.recyclerview.widget.RecyclerView$d0.itemView' on a null object reference
Stack trace: Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'android.view.View androidx.recyclerview.widget.RecyclerView$d0.itemView' on a null object reference
at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:2)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:49)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:1)
at com.codewaves.stickyheadergrid.StickyHeaderGridLayoutManager.onLayoutChildren(StickyHeaderGridLayoutManager.java:31)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:38)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:37)
at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:2)
at android.view.View.layout(View.java:20710)
at android.view.ViewGroup.layout(ViewGroup.java:6198)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20710)
at android.view.ViewGroup.layout(ViewGroup.java:6198)
at androidx.viewpager.widget.ViewPager.onLayout(ViewPager.java:258)
at android.view.View.layout(View.java:20710)
at android.view.ViewGroup.layout(ViewGroup.java:6198)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:20710)
at android.view.ViewGroup.layout(ViewGroup.java:6198)
at androidx.drawerlayout.widget.DrawerLayout.onLayout(DrawerLayout.java:56)
at android.view.View.layout(View.java:20710)
at android.view.ViewGroup.layout(ViewGroup.java:6198)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20710)
at android.view.ViewGroup.layout(ViewGroup.java:6198)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20710)
at android.view.ViewGroup.layout(ViewGroup.java:6198)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20710)
at android.view.ViewGroup.layout(ViewGroup.java:6198)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:20710)
at android.view.ViewGroup.layout(ViewGroup.java:6198)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:757)
at android.view.View.layout(View.java:20710)
at android.view.ViewGroup.layout(ViewGroup.java:6198)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2871)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2398)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1534)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7420)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1100)
at android.view.Choreographer.doCallbacks(Choreographer.java:895)
at android.view.Choreographer.doFrame(Choreographer.java:826)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1086)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6861)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
When first load data, if there have different spanSize of items in the same group, SpanSizeLookup will does not work.
can you help me to fix the issues, thank you very much!
how to collpase/expand selection? Thanks
I'm testing the library. I appreciate your work.
My question is, what's the best way for actually disabling the headers functionality?
The point is that I don't always need them on the RecyclerView
I'm using, so I'd like to be able to switch it off conditionally.
Is the recommended way to simply return empty / invisible Views from onCreateHeaderViewHolder
? This seems to do the trick, but I wonder if there was perhaps some more elegant way of accomplishing this.
I want to hide header if there is only one section in list but i am not able to fine any way to do this, if I hide main view of header then some space still there.
Hello, great work! How i can change item view type? I want use in 3 first items different view. How i can do it?
I used StickyHeaderGridAdapter and when I have added a new header and footer I can't because I can't override this final method getitemviewtype.
Getting invalid section if I perform search on list.
@OverRide
public int getSectionItemCount(int section) {
return size;
}
here section is getting more than sectioncount.
Hi, I would like to use this library. But I'm using AndroidX support libraries.
Please migrate this library to AndroidX in another repo.
i use the following code to update recyclerView content
mList.clear()
mList.addAll(list)
mStickyHeaderGridAdapter.notifyDataSetChanged()
but not work
then change to use
mStickyHeaderGridAdapter.notifyAllSectionsDataSetChanged()
still not work, is it a bug?
When scrolling the RecyclerView is presented this error. Exists solution for this error?
My Recyclerview:
StickyHeaderGridLayoutManager mLayoutManager;
mLayoutManager = new StickyHeaderGridLayoutManager(1);
rvCardapio.setLayoutManager(mLayoutManager);
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.makerdelivery.concept.makerdelivery, PID: 17594
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:4421)
at android.view.ViewGroup.addView(ViewGroup.java:4262)
at android.view.ViewGroup.addView(ViewGroup.java:4202)
at android.support.v7.widget.RecyclerView$5.addView(RecyclerView.java:754)
at android.support.v7.widget.ChildHelper.addView(ChildHelper.java:107)
at android.support.v7.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:8029)
at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:7987)
at com.codewaves.stickyheadergrid.StickyHeaderGridLayoutManager.fillBottomRow(StickyHeaderGridLayoutManager.java:514)
at com.codewaves.stickyheadergrid.StickyHeaderGridLayoutManager.addRow(StickyHeaderGridLayoutManager.java:716)
at com.codewaves.stickyheadergrid.StickyHeaderGridLayoutManager.scrollVerticallyBy(StickyHeaderGridLayoutManager.java:779)
at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:4864)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)
at android.view.Choreographer.doCallbacks(Choreographer.java:686)
at android.view.Choreographer.doFrame(Choreographer.java:618)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
In RTL languages, the first item in a grid list would be in the top right. Currently, with StickyHeaderGridLayoutManager
it's always in the top left.
The standard GridLayoutManager
allows you to specify RTL layout, for RTL language support. It'd be great if StickyHeaderGridLayoutManager
allowed you to do the same.
Hi,
There's nothing wrong with the grid but when I click an item - say section 0, item 10 - the onClick action is triggered on section 0, item 0! I log the section and position and they're always correct. here's the onBindItemViewHolder method:
`public void onBindItemViewHolder(ItemViewHolder viewHolder, final int section, final int position) {
final SubjectViewHolder holder = (SubjectViewHolder) viewHolder;
Subject subject = subjects.get(section).get(position);
holder.tvName.setText(subject.getNameEn());
Glide.with(context)
.load(subject.isSelected() ? R.drawable.ic_star_selected : R.drawable.ic_star)
.into(holder.ivSelection);
holder.tvName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e("CLICK", "SEC: " + section + " POS: " + position);
Flubber.with()
.animation(Flubber.AnimationPreset.POP)
.duration(600)
.createFor(holder.tvName)
.start();
}
});`
How can I fix this?
Hey,
I like your work but I'm stuck around a problem when I'm trying to scroll recycler view to it's one of the headers by calling scrollToPosition or smoothScrollToPosition it not scrolled at the position which I passed, I guess its scrolling to the item but I want to scroll at the desired header position, how can i do this?
Does this support horizontal scrolling? Thank you and God bless.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.