我無法將我的 textView 放在方法上綁定視圖持有者從內(nèi)部類項(xiàng),我將其公開并最終確定,但仍然無法解決它,我嘗試了許多示例,這是相同的問題。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貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超5個(gè)贊
您應(yīng)該更正適配器的通用類型:使用而不是Adapter.Item
RecyclerView.ViewHolder
public class Adapter extends RecyclerView.Adapter<Adapter.Item>
然后更新 和 方法的簽名onCreateViewHolder
onBindViewHolder
添加回答
舉報(bào)
0/150
提交
取消