0

I know this question has been asked many times but non of them solved my issues. I am trying to use CardView inside RecyclerView but no luck so far. here is my code:

<?xml version="1.0" encoding="utf-8"?>
<Android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:card_view="http://schemas.Android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_gravity="center"
  card_view:cardCornerRadius="4dp"
  card_view:cardBackgroundColor="#AA66CC"
  card_view:cardElevation="10dp"
  android:id="@+id/cv">

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_gravity="center">

  <TextView
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:id="@+id/list_item"
    android:text="asdasd asdasd tt"
    />
</RelativeLayout>

</Android.support.v7.widget.CardView>

and here is my adapter:

public class ApprovalListAdapter  extends Adapter<ApprovalListAdapter.ViewHolder> {

private String[] dataSource;
private Context mContext;
public ApprovalListAdapter(String[] dataArgs, Context context){
    dataSource = dataArgs;
    mContext = context;

}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    // create a new view
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.approval_list_row, parent, false);

    ViewHolder viewHolder = new ViewHolder(view);
    return viewHolder;


}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    holder.textView.setText(dataSource[position]);
}


@Override
public int getItemCount() {
    return dataSource.length;
}

public static class ViewHolder extends RecyclerView.ViewHolder{
    protected TextView textView;
    protected CardView cv;
    public ViewHolder(View itemView) {
        super(itemView);
        cv = (CardView) itemView.findViewById(R.id.cv);
        textView =  (TextView) itemView.findViewById(R.id.list_item);

    }
  }
}

I've also added the required dependencies

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:appcompat-v7:23.0.1'
  compile 'com.android.support:support-v4:23.0.1'
  compile 'com.android.support:recyclerview-v7:23.0.1'
  compile 'com.android.support:cardview-v7:23.0.1'
  compile 'com.android.support:design:23.0.1'
  compile project(":volley")
}

i.e CardView works perfectly fine when its not in the RecyclerView.

4
  • not works means what the exact problem you getting? Commented Oct 14, 2015 at 16:34
  • android.view.InflateException: Binary XML file line #2: Error inflating class Android.support.v7.widget.CardView @pavan Commented Oct 14, 2015 at 16:38
  • is it showing nothing or shows atleast one item Commented Oct 14, 2015 at 16:47
  • It crushes the app @pavan Commented Oct 14, 2015 at 16:47

1 Answer 1

2

You seem to have a case error, the cardview tag start by a lowercase. In your xml, replace:

<Android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" ... </Android.support.v7.widget.CardView>

with:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" ... </android.support.v7.widget.CardView>

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, that fixed my problem!!
Thanks! I typed cardview instead of CardView and got the problem too..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.