Git Product home page Git Product logo

Comments (9)

youlookwhat avatar youlookwhat commented on May 29, 2024

setStateView 可以理解为一个headerView,不知道你使用addHeaderView是否会有问题。在DiffUtil 里需要使用正确的Position,应该是需要减掉 recyclerView.getCustomTopItemViewCount()。你减去这个再试试

from byrecyclerview.

youlookwhat avatar youlookwhat commented on May 29, 2024

使用addHeaderView我试了DiffUtil 没发现问题,如果你试了后还有问题的话,我改改

from byrecyclerview.

renhuan avatar renhuan commented on May 29, 2024

setStateView 可以理解为一个headerView,不知道你使用addHeaderView是否会有问题。在DiffUtil 里需要使用正确的Position,应该是需要减掉 recyclerView.getCustomTopItemViewCount()。你减去这个再试试

我在DiffUtils之前 recyclerView.isStateViewEnabled = false 写了这句的,我看源码应该是把size置为0了,理论上不应该是position的问题

/** * Get the number of StateView */ public int getStateViewSize() { return mStateViewEnabled && mStateLayout != null && mStateLayout.getChildCount() != 0 ? 1 : 0; }

from byrecyclerview.

renhuan avatar renhuan commented on May 29, 2024

setStateView 可以理解为一个headerView,不知道你使用addHeaderView是否会有问题。在DiffUtil 里需要使用正确的Position,应该是需要减掉 recyclerView.getCustomTopItemViewCount()。你减去这个再试试

事实上我打印getCustomTopItemViewCount确实也为0

from byrecyclerview.

youlookwhat avatar youlookwhat commented on May 29, 2024

setStateView将position=0位置为状态布局,使用的是SimpleViewHolder;然而DiffUtils时positin=0会是内容的adapter,这样会出现问题。看来如果要使用setStateView,一定要使用notifyDataSetChanged()。因为position的位置会变化,这种好像也是无解的。

有一种其他的方式可以解决,不过可能不太友好,就是StateView不设置为false,设置一个0高度的布局,这样position的位置也不会变。headerview因为不会消失,所以使用DiffUtils也没问题,如果消失了可能也会出现问题。

from byrecyclerview.

renhuan avatar renhuan commented on May 29, 2024

setStateView将position=0位置为状态布局,使用的是SimpleViewHolder;然而DiffUtils时positin=0会是内容的adapter,这样会出现问题。看来如果要使用setStateView,一定要使用notifyDataSetChanged()。因为position的位置会变化,这种好像也是无解的。

有一种其他的方式可以解决,不过可能不太友好,就是StateView不设置为false,设置一个0高度的布局,这样position的位置也不会变。headerview因为不会消失,所以使用DiffUtils也没问题,如果消失了可能也会出现问题。

方法一是可以的 https://www.jianshu.com/p/2eca433869e9 ,谢啦,下班

from byrecyclerview.

renhuan avatar renhuan commented on May 29, 2024

setStateView将position=0位置为状态布局,使用的是SimpleViewHolder;然而DiffUtils时positin=0会是内容的adapter,这样会出现问题。看来如果要使用setStateView,一定要使用notifyDataSetChanged()。因为position的位置会变化,这种好像也是无解的。

有一种其他的方式可以解决,不过可能不太友好,就是StateView不设置为false,设置一个0高度的布局,这样position的位置也不会变。headerview因为不会消失,所以使用DiffUtils也没问题,如果消失了可能也会出现问题。

你觉得设置为false的时候移除StateView 可不可行

from byrecyclerview.

youlookwhat avatar youlookwhat commented on May 29, 2024

可以,我尝试一下👌

from byrecyclerview.

youlookwhat avatar youlookwhat commented on May 29, 2024
    public void setStateViewEnabled(boolean stateViewEnabled, boolean isRemoveRefresh) {
        this.mStateViewEnabled = stateViewEnabled;
        if (isRemoveRefresh && !mStateViewEnabled) {
            if (mWrapAdapter != null) {
                mWrapAdapter.getOriginalAdapter().notifyItemRemoved(getPullHeaderSize() + getHeaderViewCount());
            }
        }
    }

加了一个这个方法,可以设置 setStateViewEnabled(false,true);试试,我这边还没测试diff的情况

from byrecyclerview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.