Skip to content

Commit

Permalink
Remove unnecessary adapter item iterations when determining whether t…
Browse files Browse the repository at this point in the history
…o show a header
  • Loading branch information
starkej2 committed Oct 12, 2016
1 parent 44aec5a commit c6b10d4
Showing 1 changed file with 1 addition and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,7 @@ private boolean showHeaderAboveItem(int itemAdapterPosition) {
if (itemAdapterPosition == 0) {
return true;
}

for (int pos = itemAdapterPosition; pos >= 0; pos--) {
long posHeaderId = mAdapter.getHeaderId(pos);

if (posHeaderId != mAdapter.getHeaderId(itemAdapterPosition)) {
if (pos + 1 == itemAdapterPosition) {
return true;
}
}
}
return false;
return mAdapter.getHeaderId(itemAdapterPosition - 1) != mAdapter.getHeaderId(itemAdapterPosition);
}

/**
Expand Down

2 comments on commit c6b10d4

@krharendra
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to use it can you explain please

@krharendra
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    rvFoodAtStn.addItemDecoration(new StickyHeaderDecoration(new StickyHeaderAdapter() {
        @Override
        public long getHeaderId(int position) {
            return 0;
        }

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

        @Override
        public void onBindHeaderViewHolder(RecyclerView.ViewHolder viewholder, int position) {
               
        }
    }));

Please sign in to comment.