我是android编程的初学者,我无法理解为什么我的项目中的HomeAdapter类的onBindViewHolder实现有错误。
***This my HomeAdapter.***
这是我的课程,我想用我的recyclerview和cardview。
public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.MyViewHolder> {
private Context mContext;
private List<Products> productsList;
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView title,count;
public ImageView thumbnail,overflow;
public MyViewHolder(View itemView) {
super(itemView);
title=(TextView)itemView.findViewById(R.id.list_item);
count=(TextView)itemView.findViewById(R.id.list_count);
thumbnail=(ImageView) itemView.findViewById(R.id.thumbnail);
overflow=(ImageView) itemView.findViewById(R.id.overflow);
}
}
public HomeAdapter(Context mContext,List<Products> productsList){
this.mContext=mContext;
this.productsList=productsList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView= LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_view,parent,false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
Products products=productsList.get(position);
holder.title.setText(products.getName());
holder.count.setText(products.getNumOfProducts());
Glide.with(mContext).load(products.getThumbnail()).into(holder.thumbnail);
holder.overflow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showPopUpMenu(holder.overflow);
}
});
}
我的custom_view。 强调文字
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="5dp"
android:id="@+id/card_view"
android:elevation="3dp"
card_view:cardCornerRadius="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:scaleType="fitXY"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/list_item"
android:layout_below="@+id/thumbnail"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:textSize="15dp"
android:textColor="#8E00aa"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/list_item"
android:id="@+id/list_count"
android:textSize="12dp"
android:paddingLeft="10dp"
android:paddingBottom="5dp"
android:paddingRight="10dp"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="30dp"
android:id="@+id/overflow"
android:layout_alignParentRight="true"
android:layout_below="@+id/thumbnail"
android:layout_marginTop="10dp"
android:scaleType="centerCrop"
android:src="@drawable/navbar"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
这是onBindViewHolder上的错误
FATAL EXCEPTION: main
Process: munene.com.barberbeautyapp, PID: 22033
android.content.res.Resources$NotFoundException: String resource ID #0xd
at android.content.res.Resources.getText(Resources.java:528)
at android.widget.TextView.setText(TextView.java:4406)
at munene.com.barberbeautyapp.HomeAdapter.onBindViewHolder(HomeAdapter.java:56)
at munene.com.barberbeautyapp.HomeAdapter.onBindViewHolder(HomeAdapter.java:23).
请关注这个问题
答案 0 :(得分:2)
将此holder.count.setText(String.valueOf(products.getNumOfProducts()));
更改为products.getNumOfProducts()
。我猜int
返回@echo off
cd %~pd0
for /f "delims=" %%i in ('svnversion') do set VERSION=%%i
@echo %VERSION%
值,而android正在寻找该int值的资源值,但无法找到它。所以你应该给出字符串值。