CymChad / CymChad/BaseRecyclerViewAdapterHelper

BaseNodeAdapter如何准确获取父node的下标

Open
#3,826 0 comments 1 reaction 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

库版本:3.0.14
1、问题:
在使用BaseNodeAdapter集成树形结构的数据时(两层结构),父node和子node都添加了addChildClickViewIds,在NodeProvider的onChildClick监听其子控件的点击事件。我发现点击的position是父node和子node关联起来的,当我点击子node下的某个子控件时,想获取父node的下标(getAdapter().findParentNode(node)),此时获取的下标是动态变化的,有item折叠展开时获取的下标都不同,即有item展开时,会把子node的item都算上。
例如:A父node下有2个子node,B父node有1个子node,当点击B父node的子node想获取B父node的下标时,会有两种下标值:
1:A父node不展开的时候,获取到B父node的下标为1;
2:A父node展开时的时候,获取到B父node下标为3;
2、想实现的效果:
当我点击子node的某个子控件时,想通过getAdapter().notifyItemChanged()来单独更新其父node的数据。现在因为获取的position是不固定,所以无法通过notifyItemChanged来实现刷新。只能通过设置整个列表数据,通过notifyDataSetChanged刷新这个列表,有什么好的方法去实现吗?

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 by tracing BaseNodeAdapter's tree-position handling through NodeProvider's onChildClick callback, especially getAdapter().findParentNode(node). Compare collapsed and expanded parent nodes, then check how notifyItemChanged() differs from notifyDataSetChanged(). Done means a child-control click identifies the same parent node regardless of expansion state and updates only that parent; no source file or test is named.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.