将库添加到gradle之后:
implementation 'android.arch.paging:runtime:1.0.0'
在项目中使用PagerListAdapter时,将产生错误:
最佳答案
将以下Dependecy添加到应用程序级别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));
}
}
}