CymChad / CymChad/BaseRecyclerViewAdapterHelper
使用 GestureDetector 检测双击删除,使用 removeAt 返回的 position 不能及时刷新,使用 remove 可以正常删除
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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