我无法将我的 textView 放在方法上绑定视图持有者从内部类项,我将其公开并最终确定,但仍然无法解决它,我尝试了许多示例,这是相同的问题。package com.example.recyclerview;import android.content.Context;import android.support.annotation.NonNull;import android.support.v7.widget.RecyclerView;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.TextView;public class Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { Context context; String [] items; public Adapter(Context context, String[] items){ this.context = context; this.items = items; } @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { LayoutInflater inflater = LayoutInflater.from(context); View row = inflater.inflate(R.layout.custom_row, viewGroup, false); Item item = new Item(row); return item; } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) { String mCurrent = items[i]; viewHolder.textView.setText(mCurrent); // error here textView cannot resolve } @Override public int getItemCount() { return items.length; } public class Item extends RecyclerView.ViewHolder { public final TextView textView; public Item(@NonNull View itemView) { super(itemView); textView = (TextView) itemView.findViewById(R.id.item); } }}
1 回答
四季花海
TA贡献1811条经验 获得超5个赞
您应该更正适配器的通用类型:使用而不是Adapter.Item
RecyclerView.ViewHolder
public class Adapter extends RecyclerView.Adapter<Adapter.Item>
然后更新 和 方法的签名onCreateViewHolder
onBindViewHolder
添加回答
举报
0/150
提交
取消