无法解析onBindViewHolder中的符号textview

时间:2016-03-30 09:22:04

标签: android

enter image description here

这里mtv是TextView。而我得到一个错误无法解析符号mtv

2 个答案:

答案 0 :(得分:1)

RecyclerView.ViewHolder方法中将第一个参数从RecyclerView.ViewHolderRec更改为onBindViewHolder

答案 1 :(得分:0)

ViewHolder:

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

RecyclerView.Adapter:

@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]);

}