方法不会覆盖其超类的方法:onBindViewHolder

时间:2018-03-20 11:27:08

标签: java android recycler-adapter

我的这个问题与前一个问题不同。

我有这个基因ViewHolder for RecyclerView,

public class BaseViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {

    private CardView cardView;
    private AppCompatImageView imgEdit;
    private AppCompatImageView imgDelete;
    private ItemClickListener itemClickListener;

    public BaseViewHolder(View itemView, ItemClickListener itemClickListener) {
        super(itemView);
        cardView = itemView.findViewById(R.id.cardView);
        imgEdit = itemView.findViewById(R.id.imgEdit);
        imgDelete = itemView.findViewById(R.id.imgDelete);
        imgDelete.setOnClickListener(this);
        cardView.setOnClickListener(this);
        cardView.setOnLongClickListener(this);
        this.itemClickListener = itemClickListener;
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == cardView.getId()) {
            itemClickListener.onClick(view, getLayoutPosition(), ConstantCodes.ACTION_CLICK);
        } else if (view.getId() == imgDelete.getId()) {
            itemClickListener.onClick(view, getLayoutPosition(), ConstantCodes.ACTION_DELETE);
        } else if (view.getId() == imgEdit.getId()) {
            itemClickListener.onClick(view, getLayoutPosition(), ConstantCodes.ACTION_EDIT);
        }
    }

    @Override
    public boolean onLongClick(View view) {
        itemClickListener.onLongClick(view, getLayoutPosition());
        return false;
    }
}

这是我的RecyclerViewer的基因适配器类

public class BaseRecyclerViewAdapter extends RecyclerView.Adapter<BaseViewHolder> {

    private ItemClickListener itemClickListener;
    private List<? extends Object> objectArrayList;
    private int layout;

    public BaseRecyclerViewAdapter(int layout, ItemClickListener itemClickListener, List<? extends Object> objectArrayList) {
        this.layout = layout;
        this.itemClickListener = itemClickListener;
        this.objectArrayList = objectArrayList;
    }

    @NonNull
    @Override
    public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(layout, parent, false);
        return new BaseViewHolder(itemView, itemClickListener);
    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder holder, int position) {
    }

    @Override
    public int getItemCount() {
        return objectArrayList.size();
    }
}

当我在我的activity类中实现适配器时,它向我显示编译时错误&#34; Method不会覆盖其超类&#34;。我已经在Google和Google上检查了类似的问题在SO。您可以看到我的实现中没有输入问题。那么实际问题是什么呢?我怎么解决呢?

1 个答案:

答案 0 :(得分:0)

就我而言,我忘记了参数化我的超类。在此链接中有一个很好的答案:https://stackoverflow.com/a/40165144/3033184

希望它对其他人有用。