-1

I am new to android development. I am creating a recycler view in my mail activity.

I have defined the activity layout as:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

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

</android.support.design.widget.CoordinatorLayout>

In the MainActivity.java, when I create instance of RecyclerView, it could not resolve recycler view.

   private RecyclerView rv;

App gradle looks like:

compileSdkVersion 23
buildToolsVersion "23.0.1"
minSdkVersion 16
targetSdkVersion 23

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.android.support:recyclerview-v7:23.1.0'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.0'
    compile 'com.android.support:design:23.1.0'
}

Please tell me what I am doing wrong. Also let me know if I need to add more information.

4

2 回答 2

1

Use this:

compileSdkVersion 23
buildToolsVersion "23.0.1"
minSdkVersion 16
targetSdkVersion 23

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:recyclerview-v7:23.1.0'
    compile 'com.android.support:design:23.1.0'
}

You have multiple libraries with different versions.

于 2015-11-21T18:47:01.160 回答
0

You might want to do this in your onCreate(), after you have called setContentView(...):

rv = (RecyclerView) findViewById(R.id.recycler_view);
于 2015-11-21T18:53:07.357 回答