Android:滚动时不会调用OnbindViewHolder

时间:2018-08-18 17:23:45

标签: android android-recyclerview recycler-adapter

嗨,当recyclerview首次创建OnbindViewHolder直到recyclerview中的最后一个项目被调用时,我滚动时遇到了一个奇怪的问题 OnbindViewHolder未调用我需要解决此问题,因为我需要使用分页,但是在使用它时,它从第一次调用了所有页面 这是OnbindViewHolder函数

@Override
    public void onBindViewHolder(@NonNull EnglishNewsViewHolder holder, int position) {
        Log.d("bbb", holder.getAdapterPosition() + "");
        if ((((getItemCount()) - 1) - holder.getLayoutPosition() < 5) && !noMoreDate) {

            loadMoreDate();
        }

这就是我将项目添加到适配器

的方式
 public void add(NewsModel model, int i) {
        dataList.add(model);
        notifyItemInserted(i);
    }

这是立即创建视图而不滚动的日志。

08-18 19:58:49.958 7956-7956/qatar2022.com.qatar2022 D/bbb: 0
08-18 19:58:49.979 7956-7956/qatar2022.com.qatar2022 D/bbb: 1
08-18 19:58:49.991 7956-7956/qatar2022.com.qatar2022 D/bbb: 2
08-18 19:58:50.006 7956-7956/qatar2022.com.qatar2022 D/bbb: 3
08-18 19:58:50.020 7956-7956/qatar2022.com.qatar2022 D/bbb: 4
08-18 19:58:50.032 7956-7956/qatar2022.com.qatar2022 D/bbb: 5
08-18 19:58:50.047 7956-7956/qatar2022.com.qatar2022 D/bbb: 6
08-18 19:58:50.062 7956-7956/qatar2022.com.qatar2022 D/bbb: 7
08-18 19:58:50.077 7956-7956/qatar2022.com.qatar2022 D/bbb: 8
08-18 19:58:50.095 7956-7956/qatar2022.com.qatar2022 D/bbb: 9
08-18 19:58:50.112 7956-7956/qatar2022.com.qatar2022 D/bbb: 10
08-18 19:58:50.126 7956-7956/qatar2022.com.qatar2022 D/bbb: 11
08-18 19:58:50.139 7956-7956/qatar2022.com.qatar2022 D/bbb: 12
08-18 19:58:50.152 7956-7956/qatar2022.com.qatar2022 D/bbb: 13
08-18 19:58:50.164 7956-7956/qatar2022.com.qatar2022 D/bbb: 14
08-18 19:58:50.178 7956-7956/qatar2022.com.qatar2022 D/bbb: 15
08-18 19:58:50.194 7956-7956/qatar2022.com.qatar2022 D/bbb: 16
08-18 19:58:50.205 7956-7956/qatar2022.com.qatar2022 D/bbb: 17
08-18 19:58:50.215 7956-7956/qatar2022.com.qatar2022 D/bbb: 18

1 个答案:

答案 0 :(得分:0)

最后,我发现我必须实现nestedScrollListener的解决方案,因为recyclerview的滚动行为在NestedScrollView内部