search

Home  >  Q&A  >  body text

android - 安卓RecyclerView问题

我把RecyclerView搞了个上拉加载更多加载完以后服务器会给我一个list<String>这个list里有20个string然后我在adapter里把这个和原来合并了,那么问题来了notifyItemInserted应该传什么值?传20吗?

PHPzPHPz2856 days ago752

reply all(4)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 17:57:02

    notifyiteminserted(mcontentlist.size,list.size)//传20

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:57:02

    The new n pieces of data are inserted into the front of the list
    notifyItemRangeInserted(0, n);

    reply
    0
  • 迷茫

    迷茫2017-04-17 17:57:02

    notifyItemInserted(int position)这个方法是针对单条数据插入更新操作时使用,即在列表某个position插入一条数据,看你想做什么了。我想你需要的是notifyItemRangeInserted(int positionStart, int itemCount)这个方法,即批量添加,比如你之前已经有20条数据了,上拉加载更多新来的20条数据则是notifyItemRangeInserted(20, 20);

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:57:02

    Assume that the previous data is mLastData; the total length position= mLastData.size();
    The newly returned data is mNewData, then all the data is mLastData.addAll(mNewData);
    Use the area refresh of Recyclerview, notifyItemRangeChanged(position+1, mLastData.size());

    reply
    0
  • Cancelreply