2016-03-28 51 views
0

我在android中實現recycleview的適配器,但它引發錯誤資源ID#0x7f0d00aa類型#0x12無效。RecycleView Android崩潰與錯誤:資源ID#0x7f0d00aa類型#0x12無效

這是我的名片佈局client_info_fragment_revision_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:cardElevation="2dp" 
     android:layout_margin="7dp" 
     android:clickable="true" 
     android:focusable="true"> 

    <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" android:id="@+id/revMainLayout"> 

     <!--TOP--> 
     <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" android:id="@+id/revRelativeTop"> 
      <ImageView android:id="@+id/imagePartRevision" 
         android:layout_width="28dp" 
         android:layout_height="28dp" 
         android:scaleType="fitXY" 
         android:layout_marginLeft="7dp" android:layout_marginTop="5dp" 
         android:src="@drawable/ic_indicator_program"/> 
      <TextView 
        android:id="@+id/partRevision" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true" 
        android:maxLines="2" 
        android:padding="10dp" 
        android:text="Paper" 
        android:textSize="16sp" android:layout_marginLeft="34dp"/> 
      <TextView 
        android:id="@+id/deadlineRevision" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:text="23-04-2016" 
        android:textSize="16sp" 
        android:padding="10dp" 
        android:layout_marginRight="7dp"/> 

     </RelativeLayout> 


     <!--MIDDLE--> 
     <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" android:id="@+id/revLinearMiddle"> 
      <View 
        android:id="@+id/divider1" 
        android:layout_width="match_parent" 
        android:layout_height="1dp" 
        android:background="#a4b9adba"/> 
      <ListView 
        android:layout_width="wrap_content" 
        android:layout_height="120dp" 
        android:id="@+id/listViewRevision"/> 
      <View 
        android:id="@+id/divider2" 
        android:layout_width="match_parent" 
        android:layout_height="1dp" 
        android:background="#a4b9adba"/> 
     </LinearLayout> 

     <!--BOTTOM--> 
     <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" android:id="@+id/revRelativeBottom"> 

      <TextView 
        android:id="@+id/statusRevision" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true" 
        android:layout_toLeftOf="@+id/statusRevisionIndicator" 
        android:maxLines="2" 
        android:padding="10dp" 
        android:text="On Progress" 
        android:textSize="16sp"/> 

      <ImageView 
        android:id="@+id/statusRevisionIndicator" 
        android:layout_width="28dp" 
        android:layout_height="28dp" 
        android:layout_alignBottom="@+id/statusRevision" 
        android:layout_alignParentRight="true" 
        android:layout_below="@id/divider" 
        android:layout_marginRight="7dp" android:layout_centerVertical="true" 
        android:layout_marginBottom="5dp" android:src="@drawable/ic_indicator_not_finished"/> 
     </RelativeLayout> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 

這是代碼爲我的適配器RevisionRecycleCardsAdapter.java

package com.putraxor.prola.skripsi.client.activity.profileui; 

import android.content.Context; 
import android.support.v7.widget.RecyclerView; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.ImageView; 
import android.widget.ListView; 
import android.widget.TextView; 
import com.putraxor.prola.skripsi.R; 
import com.putraxor.prola.skripsi.pojo.Revisi; 

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 

/** 
* Created by Putra on 27/03/2016. 
*/ 
public class RevisionRecycleCardsAdapter extends RecyclerView.Adapter<RevisionRecycleCardsAdapter.CardViewHolder> { 

    private ArrayList<Revisi> revision_list; 
    Context context; 
    public static class CardViewHolder extends RecyclerView.ViewHolder{ 
     ImageView imagePartRevision; 
     ImageView statusRevisionIndicator; 
     TextView partRevision; 
     TextView deadlineRevision; 
     TextView statusRevision; 
     ListView listViewRevision; 

     public CardViewHolder(View itemView) { 
      super(itemView); 
      imagePartRevision = (ImageView)itemView.findViewById(R.id.imagePartRevision); 
      statusRevisionIndicator = (ImageView)itemView.findViewById(R.id.statusRevisionIndicator); 
      partRevision = (TextView)itemView.findViewById(R.id.partRevision); 
      deadlineRevision = (TextView)itemView.findViewById(R.id.deadlineRevision); 
      statusRevision = (TextView)itemView.findViewById(R.id.statusRevision); 
      listViewRevision = (ListView)itemView.findViewById(R.id.listViewRevision); 
     } 
    } 

    public RevisionRecycleCardsAdapter(ArrayList<Revisi> revision) { 
     this.revision_list = revision; 
    } 

    @Override 
    public CardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     this.context = parent.getContext(); 
     View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.client_info_fragment_revision_layout, parent, false); 
     CardViewHolder cardViewHolder = new CardViewHolder(view); 
     return cardViewHolder; 
    } 

    @Override 
    public void onBindViewHolder(final CardViewHolder holder, final int listPosition) { 
     Revisi rev = revision_list.get(listPosition); 
     int srcImagePartRevision = rev.getBagian().equalsIgnoreCase("Paper") ? R.drawable.ic_indicator_paper : R.drawable.ic_indicator_program; 
     int srcStateIndicator = rev.isSelesai() ? R.drawable.ic_indicator_finished : R.drawable.ic_indicator_not_finished; 
     String status = rev.isSelesai()?"Revisions Finished" : "On Process"; 
     holder.imagePartRevision.setImageResource(srcImagePartRevision); 
     holder.partRevision.setText(rev.getBagian()); 
     holder.deadlineRevision.setText(rev.getDeadline()); 
     holder.statusRevision.setText(status); 
     holder.statusRevisionIndicator.setImageResource(srcStateIndicator); 
     String[] values = rev.getRevisi(); 
     ArrayList<String> list = new ArrayList<String>(); 
     for (int i = 0; i < values.length; ++i) { 
      list.add(values[i]); 
     } 
     StableArrayAdapter adapter = new StableArrayAdapter(this.context, R.id.listViewRevision, list); 
     holder.listViewRevision.setAdapter(adapter); 
    } 

    @Override 
    public int getItemCount() { 
     return revision_list.size(); 
    } 

    private class StableArrayAdapter extends ArrayAdapter<String> { 
     HashMap<String, Integer> mIdMap = new HashMap<String, Integer>(); 
     public StableArrayAdapter(Context context, int textViewResourceId, List<String> objects) { 
      super(context, textViewResourceId, objects); 
      for (int i = 0; i < objects.size(); ++i) { 
       mIdMap.put(objects.get(i), i); 
      } 
     } 

     @Override 
     public long getItemId(int position) { 
      String item = getItem(position); 
      return mIdMap.get(item); 
     } 

     @Override 
     public boolean hasStableIds() { 
      return true; 
     } 
    } 
} 
+0

發佈您的logcat並檢查引發錯誤的行號。 – Ritesh

回答

0

改變你在

代碼
@Override 
public CardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 

    LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View view = inflater.inflate(R.layout.R.layout.client_info_fragment_revision_layout, parent, false); 
    CardViewHolder holder = new CardViewHolder (view); 
} 
0

這只是用於調試的目的:

如果您使用的是Android工作室然後打開你的R.java文件夾下的

build->generated->source->r->debug->yourpackagename->R.java

然後在文件中搜索0x7f0d00aa;它會像

public static final int TextView01=0x7f0d00aa; 

在資源文件夾下的xml文件中搜索相應的ID。然後檢查XML內容語法,命名,來源等。

相關問題