Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header view drawn multiple time #334

Closed
IHNEL opened this issue Apr 7, 2017 · 10 comments
Closed

Header view drawn multiple time #334

IHNEL opened this issue Apr 7, 2017 · 10 comments
Labels

Comments

@IHNEL
Copy link

IHNEL commented Apr 7, 2017

Hi,
I implement my recycler-view using FlexibleAdapter within AbstractHeaderItem and AbstractSectionableItem to make sticky-header list.

There are 3 list items which assigned 3 header items. 3 these header items have same data, and of course I implemented the equals method to return whether they are same. The issue is the header items drawn multiple time as below screenshot

screen shot 2017-04-07 at 11 46 41 am

If I created unique header data item and then set to all 3 items, then it draw correctly. What I am expecting is I can create header data item dynamically based on given data-fields, and there is a way to group same headers into a section.

Did I make any mistake?

@davideas
Copy link
Owner

davideas commented Apr 7, 2017

@IHNEL, well a mistake was done. Review your code to be sure the same header object is assigned to the 3 items, or maybe equals is not implemented properly. Read again the wiki for equals or simply read the method comments.

@IHNEL
Copy link
Author

IHNEL commented Apr 7, 2017

@davideas Thank for quickly reply.
I created a new header object every time insert new item. Each header object has a fieldname, and I wrote the equals like this (I'm using Kotlin) :

override fun equals(other: Any?)
= other is HeaderView && other.name == this.name

I debug and see the equals method works fine. Of course the name I set to 3 header objects is same string.

@davideas
Copy link
Owner

davideas commented Apr 7, 2017

@IHNEL, uhm theoretically it shouldn't work if you assign the same name. Can you check which is the reference in memory for the 3 header items?
Debug and watch the list in the Adapter.
Possibly assign the same object so you see the difference between the 2 approaches.

The header is displayed and inserted if it is seen as hidden, so in memory they should be different.
Also initialize the list only with items (no headers).

@davideas
Copy link
Owner

I closed due to inactivity, but also the approach used should be refined.

@IHNEL
Copy link
Author

IHNEL commented Apr 26, 2017

@davideas sorry for quite lately reply. I didn't keep good notification in Github.
Of course the memory references are difference cos I initialized 3 difference objects for header. But I think it should rely on the equals method to check that they should be on same group.

@davideas
Copy link
Owner

davideas commented Apr 26, 2017

@IHNEL, the function getHeaderOf() takes the header instance of the item, and on it is checked if it is hidden or not, then displayed, so it must be the same instance.

@IHNEL
Copy link
Author

IHNEL commented Apr 27, 2017

Ok, Got it. Seems I have to reconsider my data structure.
Thank you so much,

@IHNEL
Copy link
Author

IHNEL commented May 15, 2017

I debug and see that the method equals of header view didn't be call. I spent much of time to investigate but don't know why it runs into this case.
Any recommendation?

@davideas
Copy link
Owner

@IHNEL, the equals method is called when you get an item from the list or when it is explicity called.
With the last Snapshot I improved the calls on equals for managing Headers, check commits in issue #357.

@IHNEL
Copy link
Author

IHNEL commented May 16, 2017

Thank. Finally I found the cause.
The equals() method wasn't called if I set up the adapter like this:
adapter.setDisplayHeadersAtStartUp(true).setStickyHeaders(true)

And it works like a charm when I turn to this.

       adapter.setStickyHeaders(true)
        adapter.setStickyHeaders(true)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants