1

I have created the recyclerView and CardView in Android. Now i want to add it to one of three fragments that will be displayed on clicking the respective tabs from the navigation drawer.So how to add it in fragment.

Can anybody help me out to do so. Thank you very much!

bmnepali
  • 446
  • 11
  • 20
  • You can take a look at [my answer here](http://stackoverflow.com/questions/32678112/error-android-cardview-and-recycler-with-volley/32708983#32708983) – BNK Sep 30 '15 at 07:37

1 Answers1

2

First Add support v7 library in your project then in xml file put this.

  <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </android.support.v7.widget.RecyclerView>

Then in your fragment put these lines.

scheduler_day_view_horizontal_recyclerview = (RecyclerView) v.findViewById(R.id.my_recycler_view);
    layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
    scheduler_day_view_horizontal_recyclerview.setLayoutManager(layoutManager);
    scheduler_day_view_horizontal_recyclerview.setItemAnimator(new DefaultItemAnimator());
    scheduler_day_view_horizontal_recyclerview.setHasFixedSize(true);

Then set adapter to the RecyclerView.

For more detail about cardview and Recycler view Please visit here

Akber
  • 521
  • 4
  • 10