回收适配器定位问题

时间:2017-05-29 11:20:28

标签: java android android-recyclerview

我正在使用回收适配器来填充我的数据。问题是当我向下滚动相同的数据时正在填充示例:

05-28 20:52:09.626 adding key: setting the holder - position :0 05-28 20:52:10.533 adding key: setting the holder - position :1 05-28 20:52:10.569 adding key: setting the holder - position :2 05-28 20:52:10.916 adding key: setting the holder - position :3 05-28 20:52:11.214 adding key: setting the holder - position :4 05-28 20:52:11.494 adding key: setting the holder - position :5 05-28 20:52:11.789 adding key: setting the holder - position :6 05-28 20:52:12.033 adding key: setting the holder - position :4 05-28 20:52:12.037 adding key: setting the holder - position :5 05-28 20:52:12.041 adding key: setting the holder - position :6 05-28 20:52:12.099 adding key: setting the holder - position :7 05-28 20:52:12.212 adding key: setting the holder - position :8 05-28 20:52:13.052 adding key: setting the holder - position :9 05-28 20:52:13.340 adding key: setting the holder - position :10 05-28 20:52:13.739 adding key: setting the holder - position :11 05-28 20:52:14.185 adding key: setting the holder - position :12 05-28 20:52:14.227 adding key: setting the holder - position :13 05-28 20:52:14.481 adding key: setting the holder - position :14 05-28 20:52:14.851 adding key: setting the holder - position :15 05-28 20:52:15.032 adding key: setting the holder - position :12 05-28 20:52:15.041 adding key: setting the holder - position :13 05-28 20:52:15.044 adding key: setting the holder - position :14 05-28 20:52:15.069 adding key: setting the holder - position :15 05-28 20:52:15.174 adding key: setting the holder - position :16 05-28 20:52:15.843 adding key: setting the holder - position :17 05-28 20:52:16.181 adding key: setting the holder - position :18 05-28 20:52:16.599 adding key: setting the holder - position :19 05-28 20:52:16.631 adding key: setting the holder - position :20 05-28 20:52:16.913 adding key: setting the holder - position :21 05-28 20:52:17.378 adding key: setting the holder - position :22 05-28 20:52:17.693 adding key: setting the holder - position :23 05-28 20:52:18.082 adding key: setting the holder - position :24 05-28 20:52:18.498 adding key: setting the holder - position :25 05-28 20:52:18.844 adding key: setting the holder - position :26 05-28 20:52:19.236 adding key: setting the holder - position :27 05-28 20:52:19.713 adding key: setting the holder - position :28 05-28 20:52:19.926 adding key: setting the holder - position :25 05-28 20:52:19.928 adding key: setting the holder - position :26 05-28 20:52:19.948 adding key: setting the holder - position :27 05-28 20:52:19.972 adding key: setting the holder - position :28 05-28 20:52:20.010 adding key: setting the holder - position :29 05-28 20:52:20.783 adding key: setting the holder - position :30 05-28 20:52:20.995 adding key: setting the holder - position :31 05-28 20:52:21.178 adding key: setting the holder - position :32 05-28 20:52:21.537 adding key: setting the holder - position :33 05-28 20:52:21.908 adding key: setting the holder - position :34 05-28 20:52:22.335 adding key: setting the holder - position :35 05-28 20:52:22.607 adding key: setting the holder - position :33 05-28 20:52:22.609 adding key: setting the holder - position :34 05-28 20:52:22.611 adding key: setting the holder - position :35 05-28 20:52:22.657 adding key: setting the holder - position :36 05-28 20:52:22.891 adding key: setting the holder - position :37 05-28 20:52:23.757 adding key: setting the holder - position :38 05-28 20:52:23.968 adding key: setting the holder - position :39 05-28 20:52:23.996 adding key: setting the holder - position :40 05-28 20:52:24.285 adding key: setting the holder - position :41 05-28 20:52:24.643 adding key: setting the holder - position :42 05-28 20:52:25.134 adding key: setting the holder - position :43 05-28 20:52:25.388 adding key: setting the holder - position :44 05-28 20:52:25.680 adding key: setting the holder - position :45 05-28 20:52:26.050 adding key: setting the holder - position :46 05-28 20:52:26.345 adding key: setting the holder - position :47 05-28 20:52:26.759 adding key: setting the holder - position :48 05-28 20:52:27.060 adding key: setting the holder - position :49 05-28 20:52:27.112 adding key: setting the holder - position :46 05-28 20:52:27.114 adding key: setting the holder - position :47 05-28 20:52:27.116 adding key: setting the holder - position :48 05-28 20:52:27.134 adding key: setting the holder - position :49 05-28 20:52:27.311 adding key: setting the holder - position :50

正如你可以看到的那样,即使我向下滚动Ex:位置4,12

,也会重复这个位置

我无法粘贴源代码,因为它是保密的

提前致谢

编辑:

rv.addOnScrollListener(new EndlessRecyclerOnScrollListener(linearLayoutManager) {
                @Override
                public void onLoadMore(int current_page) { // when we have reached end of RecyclerView this event fired
                    if (canMakeRequest()) {
                        //load more data and notify adapter
                    }
                }
            });
            //load data and set adapter

2 个答案:

答案 0 :(得分:1)

覆盖getItemViewType并在recyclerview适配器中返回位置,一切都会好的。

@Override
public int getItemViewType(int position) {
    return position;
}

答案 1 :(得分:0)

我的猜测,假设您有一个textview来填充recyclerview中的名称列表,在 bindViewHolder()函数中,您需要每次都更新textview。

假设你有 if()条件来更新数据,那么替换值应该有 else 条件来更新textview,否则它只显示以前的数据。