在第 44 行抛出错误 Resources$NotFoundException holder.id.setText(record.getId());
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
private ArrayList<Record> records = new ArrayList();
public RecyclerViewAdapter(Context context, ArrayList<Rents> arrayList) {
super();
this.records= arrayList;
}
@Override
public RecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.records_item, parent, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(ViewAdapter.ViewHolder holder, int position) {
Records record = records.get(position);
Log.e("TEST",""+record.getId());
holder.id.setText(record.getId());
}
@Override
public int getItemCount() {
return records.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
private TextView id;
public ViewHolder(View itemView) {
super(itemView);
id = (TextView)itemView.findViewById(R.id.record_id);
}
}
}
A 是 XML records_item
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/record_image"
android:src="@mipmap/ic_launcher"
android:layout_margin="15dp"
android:layout_width="50dp"
android:layout_height="50dp" />
<TextView
android:id="@+id/record_id"
android:textColor="#000000"
android:layout_toRightOf="@id/record_image"
android:layout_alignTop="@id/record_image"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
该方法
TextView#setText()
有几个变体(重载)。其中之一接受许多用int
注释的类型@StringRes
。需要从应用程序的字符串资源中分配文本。你需要像这样使用它:同时,此方法(在它的重载中)将尝试
ID
通过传递给它的任何数字来查找字符串资源。这正是您的情况。在这种情况下,您需要使用接受字符串的方法的不同重载
TextView#setText(String text)
,之前已经从数字中接收到字符串,例如: