android / android/codelab-android-paging

Display header as one row in GridLayoutMnager

Open
#206 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
509
Forks
268
PR merge metrics
No merged PRs in 30d

Description

I am trying to show header as one row in Paging3 library using GridLayoutManager. For the footer as one row, I made following implementation :

```
val header = LoadStateAdapter { showAdapter.retry() }
binding.list.apply {
val layoutManager = layoutManager as GridLayoutManager
layoutManager.spanSizeLookup = object : SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return if (showAdapter.getItemViewType(position) == ShowAdapter.LOADING_ITEM)
1 else layoutManager.spanCount
}
}
adapter = showAdapter.withLoadStateHeaderAndFooter(
header = header,
footer = LoadStateAdapter { showAdapter.retry() }
)
}
```

And in the Adapter, I have following implementation :

```
override fun getItemViewType(position: Int): Int {
return if (position == itemCount) SHOW_ITEM else LOADING_ITEM
}
```

How about header? How can I display it in one row?

Contributor guide

Open the contributing guide

Research direction

Start with the GridLayoutManager SpanSizeLookup and the adapter getItemViewType implementation shown in the issue, then trace how withLoadStateHeaderAndFooter positions the header and footer. The work is done when the header and footer each occupy the full GridLayoutManager span count without disrupting item placement.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.