Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Recycler GridView list with sticky header shows two headers #149

Open
dbroy05 opened this issue Jun 14, 2017 · 2 comments
Open

Recycler GridView list with sticky header shows two headers #149

dbroy05 opened this issue Jun 14, 2017 · 2 comments

Comments

@dbroy05
Copy link

dbroy05 commented Jun 14, 2017

Just using the following to show simple GridView list with sticky headers, but I get two headers, instead of one:
`public class WSStickyHeaderAdapter extends RecyclerView.Adapter<WSStickyHeaderAdapter.SuperHolder> implements StickyRecyclerHeadersAdapter {
private final ArrayList itemsWithHeaders = new ArrayList<>(); //has first item as Header and rest actual items to be displayed.
@OverRide
public long getHeaderId(int position) {
return itemsWithHeaders.get(position).getSuperCategory().charAt(0);
}

@Override
public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.section_header, parent, false);
    return new HeaderHolder(view);
}

@Override
public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder, int position) {
    ((HeaderHolder)holder).bindItem(itemsWithHeaders.get(position));
}

@OverRide
public SuperHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
if (viewType == VIEW_TYPE_HEADER) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.section_header, parent, false);
return new HeaderHolder(view);
} else {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_giftcard, parent, false);
return new ItemHolder(view);
}
}

@Override
public void onBindViewHolder(SuperHolder holder, int position) {
    final PItem mygift = itemsWithHeaders.get(position);
    holder.bindItem(mygift);
}

@Override
public int getItemViewType(int position) {
    PItem currentItem = itemsWithHeaders.get(position);
    if (currentItem.getSku().longValue() == 0) return VIEW_TYPE_HEADER;
    else return VIEW_TYPE_ITEM;
}

@Override
public int getItemCount() {
    return itemsWithHeaders != null ? itemsWithHeaders.size():0;
}

`
So, if the first item is header "Animal", there are 4 items with Cat, Dog, Duck and Fish, it shows:

Animal
Animal
Cat Dog
Duck Fish

What am I doing wrong here?

@dbroy05
Copy link
Author

dbroy05 commented Jun 15, 2017

I got rid of two headers, now at first it shows like:

Animal
Cat Dog
Duck Fish

But when the list is scrolled up, it shows two headers text into one row like:

Animal Animal
Cat Dog
Duck Fish

@xinpengfei520
Copy link

my recyclerview have two data type , but only show one header , I don't known what's wrong ? I need help.

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

No branches or pull requests

2 participants