美文网首页
RecyclerView嵌套RecyclerView多Type布

RecyclerView嵌套RecyclerView多Type布

作者: 阡陌昏晨 | 来源:发表于2021-12-16 16:11 被阅读0次

    下面是我要实现的业务功能,当然核心就是需要RecyclerView嵌套RecyclerView


    device-2021-12-16-151435.png

    总结
    1、借助了github BaseRecyclerViewAdapterHelper第三方库适配器
    2、新增跟删除子item中的数据时候,可以使用先填充数据,然后局部刷新。或者使用全局刷新
    3、给某个子项加红色框框

    private fun addRedBg(secondPos: Int) {
            Observable.create<Long> {
                moveToPosition(recyclerView.layoutManager as LinearLayoutManager, secondPos)
                it.onNext(1)
            }
                .subscribeOn(AndroidSchedulers.mainThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object : io.reactivex.Observer<Long> {
    
                    override fun onSubscribe(p0: Disposable) {
    
                    }
    
                    override fun onNext(p0: Long) {
                        //给二级分类的最后一项加上红色框框
                        var viewHolder = recyclerView.findViewHolderForAdapterPosition(secondPos)
                        var rv = viewHolder?.itemView?.findViewById<RecyclerView>(R.id.rv)
                        val childAdapter = rv?.adapter as BaseQuickAdapter<PhotoItem, BaseViewHolder>
                        val lastPos = childAdapter?.data.size - 1
                        var childViewHolder = rv?.findViewHolderForAdapterPosition(lastPos)
                        val warnIv = childViewHolder?.itemView?.findViewById<ImageView>(R.id.warn_iv)
                        warnIv?.visibility = View.VISIBLE
                    }
    
                    override fun onError(p0: Throwable) {
                    }
    
                    override fun onComplete() {
                    }
    
                })
    
        }
    
        private fun moveToPosition(manager: LinearLayoutManager, pos: Int) {
            manager.scrollToPositionWithOffset(pos, 0);
            manager.setStackFromEnd(true);
        }
    

    相关文章

      网友评论

          本文标题:RecyclerView嵌套RecyclerView多Type布

          本文链接:https://www.haomeiwen.com/subject/itjvfrtx.html