我正在编写简单的Android应用程序 - 来自网站的书籍查找器
对于" java"关键字该应用在第一页上返回10本书。但它允许我滚动这个列表两次!我看到书重复了。
public class BookRecyclerViewAdapter extends RecyclerView.Adapter<BookImageViewHolder> {
private List<Book>booksList ;
private Context context;
private final String LOG_TAG = BookRecyclerViewAdapter.class.getSimpleName();
@Override
public void onBindViewHolder(BookImageViewHolder bookImageViewHolder, int i) {
Book book = booksList.get(i);
Picasso.with(context).load(book.getImageURL())
.error(R.drawable.book_placeholder_image)
.placeholder(R.drawable.book_placeholder_image)
.into(bookImageViewHolder.thumbnail);
bookImageViewHolder.title.setText(book.getTitle());
}
@Override
public BookImageViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.browse,null);
BookImageViewHolder bookImageViewHolder = new BookImageViewHolder(view);
return bookImageViewHolder;
}
@Override
public int getItemCount() {
if( booksList == null)
return 0 ;
else return booksList.size();
}
public BookRecyclerViewAdapter(List<Book> booksList, Context context) {
this.booksList = booksList;
this.context = context;
}
}