Search code examples
androidandroid-5.0-lollipopandroid-recyclerview

Use RecyclerView in earlier versions of Android


I want to use RecyclerView in my Android app. Following are the properties:

minSdkVersion="14" (ICS)
compile sdk version="21" (L)
Target sdk version="14" (ICS)

I added compile 'com.android.support:appcompat-v7:21.0.3' under dependencies in build.gradle file. When I'm adding RecyclerView in XML, I'm getting following error:

The following classes could not be found:
- android.support.v7.widget.RecyclerView (Fix Build Path, Create Class)

XML code:

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

I want the application to run on all devices above ICS. Please help me in resolving this issue.


Solution

  • Add the RecyclerView v7 support library to your build.gradle. There are multiple v7 libraries, each for specific features.

    compile 'com.android.support:recyclerview-v7:21.0.3'