Large pinned headers are used when the header is a separate item in the adapter. Use PinnedHeaderItemDecoration.Builder to configure the decoration.
Key configuration options:
new PinnedHeaderItemDecoration.Builder(headerType): Constructor requires the header type constant..setDividerId(resId): Sets the drawable resource for the separator line..enableDivider(true): Enables drawing the separator line (disabled by default)..setClickIds(resId): Specifies which child view IDs within the header should trigger click events..disableHeaderClick(boolean): Enables or disables the header click event (defaults to false, meaning enabled)..setHeaderClickListener(OnHeaderClickAdapter): Sets the listener for header click events.
Note: The top layer of the header cannot have a marginTop set in its layout.
```java
OnHeaderClickAdapter clickAdapter = new OnHeaderClickAdapter() {
@Override
public void onHeaderClick(View view, int id, int position) {
switch (id) {
case R.id.fl:
// case OnItemTouchListener.HEADER_ID:
Toast.makeText(StockActivity.this, "click, tag: " + mAdapter.getData().get(position).pinnedHeaderName, Toast.LENGTH_SHORT).show();
break;
case R.id.iv_more:
Toast.makeText(StockActivity.this, "click " + mAdapter.getData().get(position).pinnedHeaderName + "'s more button", Toast.LENGTH_SHORT)
.show();
break;
case R.id.checkbox:
final CheckBox checkBox = (CheckBox) view;
checkBox.setChecked(!checkBox.isChecked());
// invalidate ItemDecorations to draw the header
mRecyclerView.invalidateItemDecorations();
mAdapter.getData().get(position).check = checkBox.isChecked();
mAdapter.notifyItemChanged(position + mHeaderItemDecoration.getDataPositionOffset());
break;
}
}
};
mRecyclerView.addItemDecoration(
// Set the type of pinned header
new PinnedHeaderItemDecoration.Builder(StockEntity.StockInfo.TYPE_HEADER)
// Set separator line resources id.
.setDividerId(R.drawable.divider)
// Enable draw the separator line, by default it's disable.
.enableDivider(true)
// Set click event for the header and its internal child view.
.setClickIds(R.id.iv_more)
// Disable header click event, by default it's enable.
.disableHeaderClick(false)
// Set the listener. If the listener is not null but disable the header click event(eg. disableHeaderClick(true)), then the callback don't return.
.setHeaderClickListener(clickAdapter)
.create());
```