找不到RecyclerView

时间:2015-11-21 18:45:39

标签: android android-studio android-recyclerview recyclerview-layout

我是Android开发的新手。我正在邮件活动中创建一个回收站视图。

我已将活动布局定义为:

<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>

在MainActivity.java中,当我创建RecyclerView的实例时,它无法解析回收站视图。

   private RecyclerView rv;

App gradle看起来像:

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'
}

请告诉我我做错了什么。如果我需要添加更多信息,也请告诉我。

2 个答案:

答案 0 :(得分:1)

使用此:

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'
}

您有多个具有不同版本的库。

答案 1 :(得分:0)

在您致电onCreate()后,您可能希望在setContentView(...)中执行此操作:

rv = (RecyclerView) findViewById(R.id.recycler_view);