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

Duplicated headers appears in list during addItems first time #146

Closed
yamelkaya opened this issue Jul 21, 2016 · 11 comments
Closed

Duplicated headers appears in list during addItems first time #146

yamelkaya opened this issue Jul 21, 2016 · 11 comments

Comments

@yamelkaya
Copy link

I am not sure if it is bug or incorrect use of adapter. So, the case is following.
I use FlexibleAdapter with sticky headers.

Firstly I create adapter with empty list of items
new FlexibleAdapter(new ArrayList<ItemType>()) .

After that I load items and call addItems(0,items) and when it happens for the 1st time each sticky header duplicated in list (see screenshot). I've checked mItems in adapter just after addItems called and it has only single instance of each header.

When I call addItems 2nd, 3rd ... time there is no duplicates in list.

So, why this problem with duplicates may occur?

@davideas
Copy link
Owner

davideas commented Jul 21, 2016

Hi @yamelkaya, I am pretty sure you call showAllHeaders() twice. It is called in setDisplayHeadersAtStartUp() already, addItems() just checks if the a header is already displayed, if not it displays, so it is ok. I tried again and no duplicates.

I can improve the call of that method to avoid people call it twice with a warning.

@yamelkaya
Copy link
Author

yamelkaya commented Jul 21, 2016

Hi @davideas, I've searched over the code and I am sure that I don't call showAllHeaders() directly at all. In the constructor I just have

public class CustomAdapter extends FlexibleAdapter{

   public CustomAdapter(ItemDbProvider provider) {
        this(new ArrayList<ItemType>(),provider);
    }

   private CustomAdapter(@NonNull List<ItemType> items, ItemDbProvider provider) {
        super(items);
        setDisplayHeadersAtStartUp(true);
        enableStickyHeaders();

        this.provider = provider;
    }
...
}

@yamelkaya
Copy link
Author

I overrode showAllHeaders() to see when the second call happens but it go to this method only once - from setDisplayHeadersAtStartUp(true)

@davideas
Copy link
Owner

Ah Ok I understood, since you are using SNAPSHOT, the call of showing headers is made in Post due to a very recent fix (issue 142), but also my local branch is modified for a new improvement (issue 144) regarding post calls as well on updateDataSet(), all this caused I have different code running with no duplication.

So I will publish all these improvements and after should be fine with addItems at startUp. Need some time to test the if statement with the warning message and be sure the post calls are executed well.

What is causing the duplication to you, is that addItems displays headers because it sees it hidden, but then the post execute the showAllHeaders() resetting the hidden status (reset is necessary for the filter and update).
I am reviewing this part of code. but for now as a temporary workaround until I publish this, initialize the first part of the items in the constructor.

@yamelkaya
Copy link
Author

Ok, thanks a lot for your feedback.

@mdtuyen
Copy link

mdtuyen commented Aug 23, 2016

I have issue with sticker header. I don't know it is same your issue or not. When I refresh RecyclerView, the sticker header show not correct: sticker 1 - 2 - 3 but it show sticker 3-2-3. I need refresh again (> 1) to it show correct or touch to position of sticker 1 to it not show.

@davideas
Copy link
Owner

@mdtuyen, can you explain the exact steps to reproduce it? What do you mean when you say refresh the list, how? what you call?

I need refresh again (> 1) to it show correct or touch to position of sticker 1 to it not show.

To not show what?

@mdtuyen
Copy link

mdtuyen commented Aug 23, 2016

There are two problem in my app:

  • My recyclerview have three header (title "A1", "A2", "A3") with sticker, expandable feature. When I refresh by pull SwipeRefreshLayout I see three header is "A3", "A2", "A3" => dupplicate A3 not see "A1" (but subitem content of new "A3" is "A1"
  • Recyclerview with gridlayout, have no sticker header. Click each item => show second window with recycler have one sticker > Click back to return the first recyclerview > sticker header of second window's recyclerview show as sticker of recyclerview 1> touch to the sticker => disappear

@davideas
Copy link
Owner

davideas commented Aug 23, 2016

  1. I do not have that behavior in my demo app and I do not know how to reproduce it. For me it is impossible because from the moment you refresh the header already has the correct content: by refreshing, the sticky header, at position 0, is cleared out (layout is destroyed). I think you can enable logs and see it.

  2. I think you use fragment then because if the context were different you would not have that layout in the first RV. Read the comments I wrote in MainActivity.java in my demo app, around line 323 in the function onNavigationItemSelected().

@ivnsch
Copy link

ivnsch commented Jun 29, 2017

Hello, I also have a problem with duplicate headers. Using 5.0.0-rc2.

I'm calling updateDataSet(myItems) with a new items list after having initialized it like this ExampleAdapter(mutableListOf(), context). (Ignore for now the mutableListOf(), it should also happen with a normal (non mutable) list. Using Kotlin btw.).

I fixed it for now by waiting for the items to initialize the adapter, i.e ExampleAdapter(myItems, context)

@davideas
Copy link
Owner

@i-schuetz, when you compose the list to update, you should not add header items... please check documentation.

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

No branches or pull requests

4 participants