Coder Social home page Coder Social logo

eowise / recyclerview-stickyheaders Goto Github PK

View Code? Open in Web Editor NEW
961.0 45.0 149.0 75.68 MB

DEPRECATED. Android library that integrate sticky section headers in your RecyclerView

Home Page: http://eowise.github.io/recyclerview-stickyheaders

License: MIT License

Java 100.00%

recyclerview-stickyheaders's Introduction

recyclerview-stickyheaders

Recyclerview-stickyheaders is an Android library that makes it easy to integrate section headers in your RecyclerView. These sections headers stick to the top as you can see below :

Deprecated

I don't have enought time to maintain this lib anymore. Retrospectively, I'm not sure that ItemDecoration is the best way to implement sticky headers, especially when dynamic add, remove and reorder of items is needed. If you need sticky headers feature, have a look to SuperSLiM or FlexibleAdapter. If you are interested by taking ownership of this repository, please contact me.

recyclerview-stickyheaders's People

Contributors

leruaa avatar michaelrocks avatar robbypond avatar vovan888 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

recyclerview-stickyheaders's Issues

Error IndexOutBoundsException when multiple delete item

Firstly, thank you for your handwork, but I got issue when try to multiple delete from the bottom of item it always got IndexOutBoundsException, but if i just remove it individually it was good, and if i multiple delete from top item sometimes good sometimes got error.

java.lang.IndexOutOfBoundsException: invalid position 37. State item count is 36
at android.support.v7.widget.RecyclerView$Recycler.convertPreLayoutPositionToPostLayout(RecyclerView.java:3234)
at android.support.v7.widget.RecyclerViewHelper.convertPreLayoutPositionToPostLayout(RecyclerViewHelper.java:6)
at library.StickyHeadersItemDecoration.isHeader(StickyHeadersItemDecoration.java:110)
at library.StickyHeadersItemDecoration.onDrawOver(StickyHeadersItemDecoration.java:58)

*note i use https://github.com/writtmeyer/recyclerviewdemo for multiple delete item

ClickListeners on headers not working?

I'm trying to register a click listener on the header view or any of it's child views. However, for some reason they don't seem to be called. Is this a known issue? Have you tried that before?

Thanks,
Stefan

Handle Orientation Changes

It would be great if you could handle orientation changes. When I rotate my Device the Header is not drawn correctly. Check Screenshots

screenshot_2014-11-21-21-10-45
screenshot_2014-11-21-21-10-55

IndexOutOfBoundsException in HeaderStore

I constantly get the following exception when RecyclerView's adapter calls notifyItemChanged() for an item that has never been shown. It seems to me that HeaderStore.onItemRangeChanged() shouldn't handle this event for items with position larger than isHeaderByItemPosition.size().

    java.lang.IndexOutOfBoundsException: Invalid index 81, size is 6
            at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
            at java.util.ArrayList.set(ArrayList.java:481)
            at com.eowise.recyclerview.stickyheaders.HeaderStore.onItemRangeChanged(HeaderStore.java:219)
            at com.eowise.recyclerview.stickyheaders.StickyHeadersItemDecoration$AdapterDataObserver.onItemRangeChanged(StickyHeadersItemDecoration.java:140)
            at android.support.v7.widget.RecyclerView$AdapterDataObservable.notifyItemRangeChanged(RecyclerView.java:7503)
            at android.support.v7.widget.RecyclerView$Adapter.notifyItemChanged(RecyclerView.java:4353)
            ...

appcompat-v7: 23.0.1 can not find mRecycler

public class RecyclerViewHelper {

public static int convertPreLayoutPositionToPostLayout(RecyclerView recyclerView, int position) {
    return recyclerView.mRecycler.convertPreLayoutPositionToPostLayout(position);
}

}

Another Force Close

Hi, I just discovered a new Force Close:

java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewParent android.view.View.getParent()' on a null object reference
            at android.support.v7.widget.RecyclerView.getChildViewHolder(RecyclerView.java:2485)
            at com.eowise.recyclerview.stickyheaders.StickyHeadersTouchListener$SingleTapDetector.findItemHolderUnder(StickyHeadersTouchListener.java:78)
            at com.eowise.recyclerview.stickyheaders.StickyHeadersTouchListener$SingleTapDetector.onSingleTapConfirmed(StickyHeadersTouchListener.java:53)
            at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:273)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)

In my case I add one element with one header and then 2 other elements with another header. When I delete all items starting from the bottom, the app closes when I delete the last. (that at top)
It looks like it has to do with the on header click listener which I use.

java.lang.IndexOutOfBoundsException: invalid position 1. State item count is 1

None of my code is hit in this stack trace (see below). I am getting this error when reducing the size of my list from many to 1 with an adapter change. I've traced the source of the issue to the face that when StickyHeaderItemDecoration.drawHeaders line:53 is called, the adapter has a size of 1, parent.mState has a size of 1, but parent.getChildCount() == 2 . The second unwanted view contains data from the previous version of the list that shouldn't be there.

No matter how I notify the RecyclerView of an adapter change (notifyDataSetChanged, notifyItemRangeRemoved) the RecyclerView is out of sync with the adapter when StickyHeaderItemDecoration.drawHeaders is called - the for loop their picks up a child that should not exist.

I have a dozen classes involved in this situation, so before I take the hours required to make a simpler version of this failure, do you have any suggestions?

  java.lang.IndexOutOfBoundsException: invalid position 1. State item count is 1
            at android.support.v7.widget.RecyclerView$Recycler.convertPreLayoutPositionToPostLayout(RecyclerView.java:3316)
            at android.support.v7.widget.RecyclerViewHelper.convertPreLayoutPositionToPostLayout(RecyclerViewHelper.java:9)
            at com.eowise.recyclerview.stickyheaders.HeaderStore.isHeader(HeaderStore.java:72)
            at com.eowise.recyclerview.stickyheaders.StickyHeadersItemDecoration.drawHeaders(StickyHeadersItemDecoration.java:62)
            at com.eowise.recyclerview.stickyheaders.StickyHeadersItemDecoration.onDrawOver(StickyHeadersItemDecoration.java:44)
            at android.support.v7.widget.RecyclerView.draw(RecyclerView.java:2266)
            at android.view.View.getDisplayList(View.java:12838)
            at android.view.View.getDisplayList(View.java:12880)
            at android.view.View.draw(View.java:13657)
            at android.view.ViewGroup.drawChild(ViewGroup.java:3086)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2930)
            at android.view.View.draw(View.java:13947)
            at android.view.View.getDisplayList(View.java:12838)
            at android.view.View.getDisplayList(View.java:12880)
            at android.view.View.draw(View.java:13657)
            at android.view.ViewGroup.drawChild(ViewGroup.java:3086)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
            at android.view.View.getDisplayList(View.java:12833)
            at android.view.View.getDisplayList(View.java:12880)
            at android.view.View.draw(View.java:13657)
            at android.view.ViewGroup.drawChild(ViewGroup.java:3086)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
            at android.view.View.getDisplayList(View.java:12833)
            at android.view.View.getDisplayList(View.java:12880)
            at android.view.View.draw(View.java:13657)
            at android.view.ViewGroup.drawChild(ViewGroup.java:3086)
            at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1060)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
            at android.view.View.getDisplayList(View.java:12833)
            at android.view.View.getDisplayList(View.java:12880)
            at android.view.View.draw(View.java:13657)
            at android.view.ViewGroup.drawChild(ViewGroup.java:3086)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
            at android.view.View.getDisplayList(View.java:12833)
            at android.view.View.getDisplayList(View.java:12880)
            at android.view.View.draw(View.java:13657)
            at android.view.ViewGroup.drawChild(ViewGroup.java:3086)
            at com.jakewharton.madge.MadgeFrameLayout.drawChild(MadgeFrameLayout.java:85)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
            at android.view.View.getDisplayList(View.java:12833)
            at android.view.View.getDisplayList(View.java:12880)
            at android.view.View.draw(View.java:13657)
            at android.view.ViewGroup.drawChild(ViewGroup.java:3086)
            at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1060)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
            at android.view.View.getDisplayList(View.java:12833)
            at android.view.View.getDisplayList(View.java:12880)
            at android.view.View.draw(View.java:13657)
            at android.view.ViewGroup.drawChild(ViewGroup.java:3086)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
            at android.view.View.draw(View.java:13947)
            at android.widget.FrameLayout.draw(FrameLayout.java:467)
            at android.view.View.getDisplayList(View.java:12838)
            at android.view.View.getDisplayList(View.java:12880)
            at android.view.View.draw(View.java:13657)
            at android.view.ViewGroup.drawChild(ViewGroup.java:3086)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
            at android.view.View.draw(View.java:13947)
            at android.support.v7.internal.widget.ActionBarOverlayLayout.draw(ActionBarOverlayLayout.java:509)
            at android.view.View.getDisplayList(View.java:12838)
            at android.view.View.getDisplayList(View.java:12880)
            at android.view.View.draw(View.java:13657)
            at android.view.ViewGroup.drawChild(ViewGroup.java:3086)
            at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
            at android.view.View.getDisplayList(View.java:12833)
            at android.view.View.getDisplayList(View.java:12880

Header View children cannot be resized

Any children with width=wrap_content have a size fixed at inflation, even when content is added to them. e.g. a TextView. Calling requestLayout or setLayoutParams with a fixed width also has no effect.

Problem with GridLayoutManager

When i try to use GridLayoutManager instead LinearLayoutManager all items look awful. I have not found information about support GridLayoutManager. Is it my problem or lib bug?
s50116-174047

Sticky headers using ItemDecoration doesn't display well on remove item

Item removing is animated so items under removed item are smoothly translated up. But ItemDecoration onDrawOver() is only called once when remove animation is started. So headers under removed item cannot be animated.

A workaround could be using a LayoutManager wrapper. Still searching...

Sometimes header do not push header on top of them when reaching the top of the views.

Hi,
Sometimes, when a header reach the top of the view (when scrolling down in a list for example), the header do not replace the one above him, but instead is drawn under the current top header. When the "future" top header reach totally the top of the view, it is finally correctly draw above the old header at top.

What could occurs is that the "old" top header is not always correctly animated ?

If needed, I can provide a sample project.

Headers aren't animated when using an ItemAnimator

I'm using "setItemAnimator(...)" on the recyclerView to use animations when adding/deleting items. The items are correctly animated, but the headers aren't animated at all. They do move correctly but aren't animated.
Issue #26 may be related.

Headers does not get updated when notifyItemMoved is called

I am having a list with the following structure.
Header1
Item1
Item2
Item3
Header2
Item4
Header3
item5

When I try to move the last three items to bottom of the list using notifyItemMoved I get the following the result

Header2
Item4
Item5
Item1
Header1
Item2
Header1
Item3

Calling notifydatasetChanged fixes this and produces the correct list
Header2
Item4
Header3
Item5
Header1
Item1
Item2
Item3
But that makes the animation of the notifyItemMoved look very weird

For me it looks like the placement of the headers does not get updated only the content of the already placed headers does get updated.

Header Move When Removing Position 0

If position 0 is removed, and position 1 returns the same header id as position 0, the header will slide down to the top of position 1 while position 0 is animating out. It then slides back to the top as position 1 becomes the new position 0. This has a very jarring effect on the animation of the RecyclerView items.

Warnings when building project

Hi, I have an issue when using your library.
When I try to build my project with the command 'gradle build', I get the following warnings:

Warning: com.eowise.recyclerview.stickyheaders.HeaderStore$1: can't find referenced method 'android.support.v7.widget.RecyclerView access$100(com.eowise.recyclerview.stickyheaders.HeaderStore)' in program class com.eowise.recyclerview.stickyheaders.HeaderStore
Warning: com.eowise.recyclerview.stickyheaders.HeaderStore$1: can't find referenced class com.eowise.recyclerview.stickyheaders.HeaderInfo
Warning: com.eowise.recyclerview.stickyheaders.HeaderStore$1: can't find referenced class com.eowise.recyclerview.stickyheaders.HeaderInfo
Warning: com.eowise.recyclerview.stickyheaders.HeaderStore$1$1: can't find referenced class com.eowise.recyclerview.stickyheaders.HeaderInfo
Warning: com.eowise.recyclerview.stickyheaders.HeaderStore$1$1: can't find referenced class com.eowise.recyclerview.stickyheaders.HeaderInfo
Warning: com.eowise.recyclerview.stickyheaders.HeaderStore$1$1: can't find referenced class com.eowise.recyclerview.stickyheaders.HeaderInfo
Warning: com.eowise.recyclerview.stickyheaders.HeaderStore$1$1: can't find referenced method 'java.util.HashMap access$000(com.eowise.recyclerview.stickyheaders.HeaderStore)' in program class com.eowise.recyclerview.stickyheaders.HeaderStore
Warning: com.eowise.recyclerview.stickyheaders.HeaderStore$1$1: can't find referenced class com.eowise.recyclerview.stickyheaders.HeaderInfo
Warning: com.eowise.recyclerview.stickyheaders.HeaderStore$1$1: can't find referenced class com.eowise.recyclerview.stickyheaders.HeaderInfo
Warning: there were 7 unresolved references to classes or interfaces.

I am using the library this way:

dependencies {
compile 'com.eowise:recyclerview-stickyheaders:0.5.1@aar'
}

So my project build fails with this exception:

FAILURE: Build failed with an exception.

java.io.IOException: Please correct the above warnings first.

Do you know what might be the problem?
Thank you very much in advance

A new way to display Sticky Headers

I wanted to test this project, but as the author said, it is deprecated, so I've worked on my implementation of the sticky headers still using a custom ItemDecoration but with a lot of advantages...
The project is https://github.com/davideas/FlexibleAdapter. Adding, removing, dragging items are also covered, header is automatically re-linked to the item below.

For information, I've also written an answer at this question: http://stackoverflow.com/questions/33018788/how-can-i-set-a-listener-inside-a-recyclerview-header-decor

EDIT of 29/03/2016
Sticky Headers are now clickable using same listeners of the ViewHolder, not using anymore ItemDecoration. A FrameLayout is instead used.

Finally, I agree with the author when he says that ItemDecoration is not the good way for sticky headers, and a custom LayoutManager or a ViewGroup should handle the HeaderView object. So I am searching help for this. The project SuperSlim is based on the LayoutManager, but it is a huge library: ~3400 lines for sections and sticky headers only(!?). However I did not test it for compatibility with my project.

Header is drawn on top of scrollbar

When scrolling RecycleView it is clearly visible that headers overlay scrollbar, looks like scrollbar is under the header.

My header layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?listPreferredItemHeightSmall"
    android:background="@color/background_color"
    android:paddingTop="8dp"
    android:paddingStart="8dp"
    android:paddingEnd="8dp">

    <TextView
        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:textAppearance="@style/TextAppearance.AppCompat.Title" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:src="?android:listDivider"
        android:scaleType="fitXY"/>

</FrameLayout>

Calendar Day Headers

possible
I've been trying to use your library in order to create the picture above. Is it possible? How should I do it? I've failed miserably in order to create it.

how can I update the header ๏ผŸ

for example , i have got a checkbox on my header , I want to update the checkBox when I click the header (include the stickyHeader)
how can I make it works ?
Obviously , there is no method like "notifyDataSetChange" in StickyHeaderApapter

Ownership takeover

I'm looking for someone to take over this project. I'm switching gears into a different type of development and will not be able to give this project the attention it may need.

If you are interested, you can reply here.

Using CursorAdapter returns "Adapter must have stable ids" error

I'm not positive if I'm doing something incorrect here. My CursorAdapter uses the primary column id as the adapter id and I override setHasStableIds like so:

private Cursor mCursor;

private boolean mDataValid;

private int mRowIdColumn;

private DataSetObserver mDataSetObserver;

public CursorRecyclerViewAdapter(Cursor cursor) {
    mCursor = cursor;
    mDataValid = cursor != null;
    mRowIdColumn = mDataValid ? mCursor.getColumnIndex("_id") : -1;
    mDataSetObserver = new NotifyingDataSetObserver();
    if (mCursor != null) {
        mCursor.registerDataSetObserver(mDataSetObserver);
    }
}

...

@OverRide
public long getItemId(int position) {
if (mDataValid && mCursor != null && mCursor.moveToPosition(position)) {
return mCursor.getLong(mRowIdColumn);
}
return 0;
}

@Override
public void setHasStableIds(boolean hasStableIds) {
    super.setHasStableIds(true);
}

However, I keep getting the above error message when trying to implement your library. Is there some kind of problem with using a CursorAdapter as the underlying adapter for the RecyclerView? Perhaps I'm implementing this incorrectly? Thanks for your attention

IndexOutOfBoundsException when deleting the last item

Hi, with the latest version (0.4.3) I get a IndexOutOfBoundsException (Invalid index 0, size is 0) when I delete the last item from my Adapter.

This is the code I use:

public void deleteVocable(Vocable vocable) {
        for (int i = 0; i < data.size(); i++) {
            if (vocable.getId() == data.get(i).getId()) {
                data.remove(i);
                this.notifyItemRemoved(i);
                break;
            }
        }
    }

Does this work with GridLayoutManager?

I have a grid layout manager which contains 2 items per row.
They are ordered in time descend. But I wanna add sticky headers to split them into different days

Is that possible.

I have tried this library with my project, it seems not to work currently

Thanks

Hide the header for some data

Hello, thanks for that early library !
I would like to know if it is possible to disable the sticky headers for some rows ? I means, would it be possible to ignore rows which return a negative number through getHeaderId() by example ?
In facts I need to start displaying sticky headers only for index 1 and more (and thus ignore row at index 0).

I tried to hide the header by setting its visibility to GONE in the method onBindViewHolder, but the corresponding header is still draw.

Any idea how to implement such behavior ?

Thanks you

RecyclerView Adapter Issue

When we update , add ,delete an item from Adapter , or Attach a new Adapter to RecyclerView when in Sticky mode , lots of White Space appear between sticky header and Recycler View

it is just because of Translation Y

Header Click Listener

Hi, when I set a HeaderClickListener and then click on a header the View under the header receives also a click event. In my case two Dialogs open, which is ugly and unintended,

HeaderStore Doesn't Observe Move or Change

Since the HeaderStore doesn't observe onItemRangeMoved or onItemRangeChanged, headers don't update unless Adapter#notifyDataSetChanged is called which screws up animations.

Header jumps when inserting new Items at bottom

When adding new items at the bottom of the list when the header has reached the top of the list the header jumps one item down and then makes the animation up to the top. Again and again.

Any ideas about that?

Load network imageview in header

I am using your library to create a header which contains imageview whoes image comes from internet url ..
for asyncronous image downloading and loading i m using another library glide , which takes imageview as input .

So i have made an adapter that implements StickyHeaderAdapter whoes layout contains the imageview
and in onBind function of my adapter I have called the asynchronusly loading Util from glide ,,
the util works properly it fecthes the image from network asynchronously and updates the image view however your draw headers function does not draw it ..!
the on bind call from the stickyheader is called how ever the image is not displayed...in the header .. how do i do this ,,,!??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.