我收到错误:class" FlickrRecyclerViewAdapter"必须在'适配器'
中声明为abstract或实现方法抽象方法onBindViewHolder(VH,int)虽然这个错误应该是自我解释的,但我已经实现了onBindViewHolder并且错误仍然存在。
Relvant Code -
public class FlickrRecyclerViewAdapter extends RecyclerView.Adapter {
private List<Photo> mPhotosList;
private Context mContext;
public FlickrRecyclerViewAdapter(Context context, List<Photo> photosList) {
mContext = context;
this.mPhotosList = photosList;
}
@Override
public void onBindViewHolder(FlickrImageViewHolder flickrImageViewHolder, int i) {
Photo photoItem = mPhotosList.get(i);
Picasso.with(mContext).load(photoItem.getmImage())
.error(R.drawable.placeholder)
.placeholder(R.drawable.placeholder)
.into(flickrImageViewHolder.thumbnail);
}
}
由于
答案 0 :(得分:8)
适配器的定义是
RecyclerView.Adapter<VH extends android.support.v7.widget.RecyclerView.ViewHolder>
其中VH
是ViewHolder
的子类。所以你可以改变onBindViewHolder的签名,如
@Override
public void onBindViewHolder(RecyclerView.ViewHolder flickrImageViewHolder, int i) {
或更改
extends RecyclerView.Adapter {
带
extends RecyclerView.Adapter<FlickrImageViewHolder> {
答案 1 :(得分:0)
RecyclerView.Adapter
有一个方法:
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
你必须覆盖。使用您正在使用的方法签名,您必须像这样扩展:
public class FlickrRecyclerViewAdapter extends RecyclerView.Adapter<FlickrImageViewHolder>