CymChad / BaseRecyclerViewAdapterHelper

BRVAH:Powerful and flexible RecyclerAdapter
http://www.recyclerview.org/
MIT License
24.2k stars 5.14k forks source link

BaseExpandNode 出现错位问题 #3807

Closed muzitianya closed 9 months ago

muzitianya commented 9 months ago

使用BaseExpandNode作为父节点,BaseNode作为子节点,父节点下的子节点通过接口请求下来动态添加进去,在父节点有个loading,点击父节点请求网络出现loading, 但是数据添加进来之后,loading位置跑到别的父节点上去了

class FirstNodeProvider( override val itemViewType: Int, override val layoutId: Int, val click: (schema_directory_id: Int) -> Unit ) : BaseNodeProvider() { override fun convert(helper: BaseViewHolder, item: BaseNode) { val firstNode = item as? FirstNode helper.setText(R.id.tv_title, firstNode?.title) if (firstNode is BaseExpandNode) { val view = helper.getView(R.id.iv_arrow) view.rotation = if (firstNode.isExpanded) -180f else 0f } }

override fun onClick(helper: BaseViewHolder, view: View, data: BaseNode, position: Int) {
    super.onClick(helper, view, data, position)
    if (data is FirstNode) {
        if (data.isExpanded) {
            getAdapter()?.expandOrCollapse(position, animate = false)
        } else {
            // 数据为空,请求接口,否则直接展开
            if (data.childNode.isNullOrEmpty()) {
                data.schema_directory_id.let {
                    if (it == null) {
                        showToast("数据错误,请刷新重试")
                    } else {
                        // 展示loading
                        helper.setVisible(R.id.sync_learn_progress, true)
                        helper.setVisible(R.id.iv_arrow, false)
                        click(it)
                    }
                }
            } else {
                getAdapter()?.expandAndCollapseOther(position, animate = false)
            }
        }
    }
}

}

通过这种方法添加数据 nodeReplaceChildData()