必须将onBindViewHolder声明为abstract

时间:2015-10-31 17:54:14

标签: java android android-studio android-recyclerview picasso

我收到错误: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);

        }
    }

由于

2 个答案:

答案 0 :(得分:8)

适配器的定义是

RecyclerView.Adapter<VH extends android.support.v7.widget.RecyclerView.ViewHolder>

其中VHViewHolder的子类。所以你可以改变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>