CymChad / CymChad/BaseRecyclerViewAdapterHelper

convert() invoke wrong UI re-draw by scroll in adapter with multiItemEntity

Open
#3,248 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
24.6k
Forks
5.2k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug
Use: BaseMultiItemQuickAdapter
When Scrolling,
convert(holder: BaseViewHolder, item: AttitudeMutiEntity) will invoke,
then re-draw UI.
I have already checked the data not changed when scrolling.

To Reproduce
Steps to reproduce the behavior:

  1. show up the recycler view UI
  2. Scrolling up and down
  3. See error UI

Expected behavior
only tickNum = 0 to change visibility

Error behavior
when scrolling, tickNum != 0 also change visibility

Additional context

class AttitudeAdapter(data: MutableList<AttitudeMutiEntity>) :
    BaseMultiItemQuickAdapter<AttitudeMutiEntity, BaseViewHolder>(data) {
    var middle =
        if (data.size % 2 == 1) data.size/2 +1
        else data.size /2

    init {
        logd("data: $data")
        addItemType(AttitudeMutiEntity.MAJOR, R.layout.item_atti_tick_major)
        addItemType(AttitudeMutiEntity.MINOR, R.layout.item_atti_tick_minor)
    }

    override fun convert(holder: BaseViewHolder, item: AttitudeMutiEntity) {
        logd("data: $data")

        if (item.tickNum == 0 && item.itemType == AttitudeMutiEntity.MAJOR){
            logd("invisible")
            holder.getView<TextView>(R.id.tVtickNumL).visibility = View.INVISIBLE
            holder.getView<TextView>(R.id.tVtickNumR).visibility = View.INVISIBLE
            holder.getView<View>(R.id.tick).visibility = View.INVISIBLE
        }
        holder.getView<TextView>(R.id.tVtickNumL).text = "${item.tickNum}"
        holder.getView<TextView>(R.id.tVtickNumR).text = "${item.tickNum}"
}

implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with BaseMultiItemQuickAdapter and the AttitudeAdapter convert() implementation shown in the issue. Reproduce the RecyclerView scrolling case, then inspect how recycled item views handle visibility for different tickNum values; done means scrolling no longer changes visibility for items whose tickNum is not zero.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.