为了账号安全,请及时绑定邮箱和手机立即绑定

[Android] [RecyclerView]方法不会覆盖或实现超类型的方法

[Android] [RecyclerView]方法不会覆盖或实现超类型的方法

烙印99 2021-05-07 18:42:21
我正在按照本教程开发一个简单的Android应用程序。我在此消息的onBindViewHolder方法上遇到编译错误:错误:方法未覆盖或从超类型实现方法这是我的代码:import android.support.annotation.NonNull;import android.support.v7.widget.RecyclerView;import android.view.LayoutInflater;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.TextView;public class CryptogramPairingAdapter extends RecyclerView.Adapter {    private String[] mDataset;    // Provide a reference to the views for each data item    // Complex data items may need more than one view per item, and    // you provide access to all the views for a data item in a view holder    public static class ViewHolder extends RecyclerView.ViewHolder {        // each data item is just a string in this case        public TextView mTextView;        public ViewHolder(TextView v) {            super(v);            mTextView = v;        }    }    // Provide a suitable constructor (depends on the kind of dataset)    public CryptogramPairingAdapter(String[] myDataset) {        mDataset = myDataset;    }    // Create new views (invoked by the layout manager)    @Override    public ViewHolder onCreateViewHolder(ViewGroup parent,                                                   int viewType) {        // create a new view        TextView v = (TextView) LayoutInflater.from(parent.getContext())                .inflate(R.layout.pair_crypto_recyclerview, parent, false);        CryptogramPairingAdapter.ViewHolder vh = new ViewHolder(v);        return vh;    }    // Replace the contents of a view (invoked by the layout manager)    @Override    public void onBindViewHolder(ViewHolder holder, int position) {        // - get element from your dataset at this position        // - replace the contents of the view with that element        holder.mTextView.setText(mDataset[position]);    }    // Return the size of your dataset (invoked by the layout manager)    @Override    public int getItemCount() {        return mDataset.length;    }}我很困惑,因为代码与引用几乎相同(除了修改后的名称)。
查看完整描述

1 回答

?
慕少森

TA贡献2019条经验 获得超9个赞

我建议你改变你的ViewHolder被命名为比其他的东西ViewHolder,因为它是有冲突的ViewHolder,并简单地去给你带来的混乱区分ViewHolderViewHolder

我在他们的示例中向Google抱怨这种糟糕的做法

给定当前状态的代码,请更改:

public class CryptogramPairingAdapter extends RecyclerView.Adapter

至:

public class CryptogramPairingAdapter extends RecyclerView.Adapter<CryptogramPairingAdapter.ViewHolder>



查看完整回答
反对 回复 2021-05-19
  • 1 回答
  • 0 关注
  • 512 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信