实现 android.arch.paging:runtime:1.0.0

Implementation android.arch.paging:runtime:1.0.0

将库添加到 gradle 后:

implementation 'android.arch.paging:runtime:1.0.0'

在项目中使用PagerListAdapter,产生错误:

"Add library 'Gragle: android.arch.paging:runtime-1.0.0' tо classpath"

将以下依赖项添加到应用级别 gradle 文件中。

implementation "android.arch.paging:runtime:1.0.0-alpha4-1"

并像下面的代码一样检查您的适配器..

public class UserAdapter extends PagedListAdapter<User, UserAdapter.UserItemViewHolder> {


public UserAdapter() {
    super(User.DIFF_CALLBACK);
}

@Override
public UserItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
    View view = layoutInflater.inflate(R.layout.item_user_list, parent, false);
    return new UserItemViewHolder(view);
}

@Override
public void onBindViewHolder(UserItemViewHolder holder, int position) {
    User user= getItem(position);
    if(user!=null) {
        holder.bindTo(user);
    }
}

static class UserItemViewHolder extends RecyclerView.ViewHolder {
    TextView userName, userId;

    public UserItemViewHolder(View itemView) {
        super(itemView);
        userId = itemView.findViewById(R.id.userId);
        userName = itemView.findViewById(R.id.userName);
    }

    public void bindTo(User user) {
        userName.setText(user.firstName);
        userId.setText(String.valueOf(user.userId));
    }
}
}