Android:onBindViewHolder()在网站上显示两次图书清单

时间:2015-03-20 16:38:26

标签: java android list android-viewholder

我正在编写简单的Android应用程序 - 来自网站的书籍查找器

对于" java"关键字该应用在第一页上返回10本书。但它允许我滚动这个列表两次!我看到书重复了。 list

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;
}

}

0 个答案:

没有答案