Prevent the adapter from recycling views on scroll ( Edit do not ever do this.)

后端 未结 4 1180
走了就别回头了
走了就别回头了 2020-12-16 04:35

I have a custom base adapter that will take in an arraylist of data. From here it will fill out a grid view with custom buttons. It does so perfectly and fills up the gridvi

4条回答
  •  借酒劲吻你
    2020-12-16 05:29

    A better approach would be using

    recyclerView.getRecycledViewPool().setMaxRecycledViews(VIEW_TYPE,0);

    You must note that this may reduce the performance of your RecyclerView.

    You can Override the getItemViewType method as mentioned below

    @Override
    public int getItemViewType(int position) {
        if (position == feedElements.size())
            return 3;
        else if (feedElements.get(position).getType() == 1)
            return 1;
        else
            return 2;
    }
    

提交回复
热议问题