Search code examples
androidandroid-studioandroid-recyclerviewandroid-cardview

How to use RecyclerView and CardView


I don't have much experience in android development and try to implement RecyclerView in my application. The version of android studio does not have Android L neither there is option to install. Everytime it says android.support.widget.v7.RecyclerView in not used and disabled it from import packages. I give refrences in layout file also in Gradle.build but my problem is still there anyone help please?


Solution

  • Follow this line

    • CardView and RecyclerView in Material Design

    http://icetea09.com/blog/2014/12/19/android-cardview-and-recyclerview-in-material-design/

    add these into the dependencies:

        compile 'com.android.support:cardview-v7:22.2.0'
        compile 'com.android.support:recyclerview-v7:22.2.0'
    

    and update the gradle in module's build.gradle

    • Example for each one:

    CardView

    <android.support.v7.widget.CardView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        card_view:contentPadding="16dp"
        card_view:cardElevation="2dp"
        card_view:cardCornerRadius="5dp">
    
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    
            <TextView
                style="@style/Base.TextAppearance.AppCompat.Headline"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Title" />
    
            <TextView
                style="@style/Base.TextAppearance.AppCompat.Body1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Content here" />
    
        </LinearLayout>
    
    </android.support.v7.widget.CardView>
    

    RecyclerView:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    
    </LinearLayout>