在recyclerview中删除项目后更新SpanSizeLookup

时间:2016-03-02 12:31:56

标签: android android-recyclerview android-gridlayout

我使用GridLayoutManager进行recyclelerview,其spansize为1和2

GridLayoutManager.SpanSizeLookup spanSizeLookup = new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            switch (adapter.getItemViewType(position)) {
                case TYPE_HEADING:
                    return 1;
                default:
                    return 2;
            }
        }
    };
RecyclerAdapter adapter = new RecyclerAdapter(mContext, arrItems);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setAdapter(adapter);

Recyclerview完美呈现。但是如果我从recyclerview中删除一个项目,则spansize反转,即TYPE_HEADING的spansize变为2,否则为1。

删除项目的代码。

arrItems.remove(position);
notifyItemRemoved(position);

如何解决此问题

0 个答案:

没有答案