Reputation: 8042
I want to implement the sticky gridview
in my application but the problem is that my header of the gridview
is also move when I scroll the gridview
, So could you please help me to sort out from these problem
Upvotes: 1
Views: 3076
Reputation: 41
TonicArtos's repo is great, but I found it hard to integrate it with my app. Also, I couldn't get the example code to run so I decided to fork it and improve it a little bit.
The only thing that was added was 2 classes that makes the creation of the adapter a lot easier IMO.
The first of those classes is:
public abstract class UtilAdapter<T, VH extends BaseViewHolder> extends BaseAdapter {
//methods to add and remove elements & viewholder implementation
}
This class provides some methods to add and remove elements from an internal list it has (kind of what ArrayAdapter does). It also implements the viewholder pattern for you so you just have to implement a few abstract methods.
The second class is:
public abstract class StickyGridAdapter<T, VH extends BaseViewHolder, HVH extends BaseViewHolder> extends UtilAdapter<T, VH> implements StickyGridHeadersSimpleAdapter {
//viewholder imlpementation for the header view (also has abstract methods)
}
This class implements StickyGridHeadersSimpleAdapter (TonicArtos's interface). It also implements the viewholder pattern for the header views, so extending this class makes you implement a few methods that return ViewHolder classes and other methods that populate said viewholders.
To implement a sticky header grid you just have to extend StickyGridAdapter, use StickyGridHeadersGridView instead of GridView in your layout and set the adapter as usual.
Here is a link to the repo (which is a fork of TonicArto's):
https://github.com/OneCodeLabs/StickyGridHeaders
I also wrote some example code using my classes. I hope it can help you
Upvotes: 1
Reputation: 23638
You can check out StickyGridHeaders
is library that provides a GridView
that shows items in sections with headers. By default the section headers stick to the top like the People app in Android 4.x but this can be turned off.
StickyGridHeaders also automatically sizes its rows to the largest item in the row.
Another is AStickyHeader for adding Sticky Headers to ListView or GridView.
Hope this will help you.
Upvotes: 1