2017-02-23 3 views
0

Ich bin ein Anfänger in Android-Programmierung und ich kann nicht verstehen, warum ein Fehler auf OnBindViewHolder Implementierung der HomeAdapter-Klasse in meinem Projekt ist.Fehler auf meinem onBindViewHolder in Android

***This my HomeAdapter.*** 

Das ist meine Klasse, die ich mit meinem recyclerview und cardview verwenden möchten.

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

     } 

mein custom_view. betonte Text

<?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> 

und das ist der Fehler auf 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). 

zu diesem Problem bitte

+0

Auf welcher Zeile bekommen Sie Fehler? Ihre Textansicht wurde nicht gefunden, aber der Code ist korrekt. Bitte zeigen Sie mir Zeile auf whihc Sie bekommen Fehler –

+0

HomeAdapter.java:56 Zeile Nr. 56 von HomeAdapter ist? Bitte senden Sie den 56. Zeilencode –

+0

@PETERSON, Markieren Sie bitte Ihre 56. Codezeile? Wo der Fehler tatsächlich auftritt. Es ist ziemlich schwer, aus diesen massiven Codeblöcken herauszufinden. –

Antwort

2

ändern diese holder.count.setText(products.getNumOfProducts());-holder.count.setText(String.valueOf(products.getNumOfProducts())); asist. Ich denke products.getNumOfProducts() gibt einen int Wert zurück und Android sucht nach einem Ressourcenwert für diesen int Wert und kann es nicht finden. Sie sollten also Zeichenfolge Wert geben.

+0

Danke..es hat funktioniert –

+0

Ich bin froh, das zu hören. Vielleicht solltest du es als richtige Antwort markieren. Vielen Dank ;) – faranjit

Verwandte Themen