CymChad / CymChad/BaseRecyclerViewAdapterHelper

使用 GestureDetector 检测双击删除,使用 removeAt 返回的 position 不能及时刷新,使用 remove 可以正常删除

Open
#3,878 1 comment 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

注意

我的是RecyclerView 是多层嵌套的

private val gestureDetector =
GestureDetector(context, object : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
return true
}

        override fun onDoubleTap(e: MotionEvent): Boolean {
            val child = recyclerView.findChildViewUnder(e.x, e.y)
            child?.let {
                val position = recyclerView.getChildAdapterPosition(it)
                if (position != RecyclerView.NO_POSITION) {
                    listener.onItemDoubleClick(it, position)
                }
            }
            return true
        }
    })
双击删除后,返回的 postion 并不是 最新的

使用 BaseQuickAdapter 自带的 removeAt(postion)传入 listener.onItemDoubleClick(it, position)返回的 postion 会出现数组下标越界

使用 BaseQuickAdapter 自带的 remove(item)传入 删除的是正常的

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 the GestureDetector onDoubleTap flow shown in the issue, especially findChildViewUnder, getChildAdapterPosition, and listener.onItemDoubleClick. Compare the behavior of BaseQuickAdapter removeAt(position) with remove(item) in a nested RecyclerView case. Done means double-click deletion uses a current valid position and does not produce an array-index error.

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.