将库添加到gradle后:
Idno
使用项目中的PagerListAdapter,会产生错误:
“添加库'Gragle:android.arch.paging:runtime-1.0.0'classpath”
答案 0 :(得分:1)
将以下依赖项添加到应用程序级别的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));
}
}
}