找不到getAdapterPosition()作为方法

时间:2017-03-08 08:36:23

标签: android android-studio android-recyclerview

我最近升级到Android Studio 2.3而不能找到getAdapterPosition(RecyclerView)。我在网上看到,原因是支持库版本。但我不知道如何解决它。我的支持:appcompat-v7:25.2.0'版本是最新版本(例如21以上)。我不明白为什么找不到这个方法。请问有什么建议吗?

compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile files('libs/wekaSTRIPPED.jar')
compile('com.mikepenz:materialdrawer:5.8.1@aar') { // Material Drawer
    transitive = true
}
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.jakewharton:butterknife:8.5.1'
compile 'com.google.dagger:dagger:2.9'
compile 'com.github.wendykierp:JTransforms:3.1'
compile 'com.afollestad.material-dialogs:commons:0.9.3.0'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.github.paolorotolo:appintro:4.1.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.borax12.materialdaterangepicker:library:1.9'
compile 'com.evernote:android-job:1.1.7' // Scheduling library
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
annotationProcessor 'com.google.dagger:dagger-compiler:2.9'

4 个答案:

答案 0 :(得分:5)

请检查您是否在ViewHolder Class中使用此方法?

getAdapterPostion() RecyclerView.ViewHolder 的方法。

您需要确保在扩展 RecyclerView.ViewHolder

的类中使用此方法

答案 1 :(得分:2)

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

可能会错过那条线???

答案 2 :(得分:1)

请添加此依赖项:   编译'com.android.support:recyclerview-v7:23.3.0'

答案 3 :(得分:1)

也可能你必须使用buildToolsVersion 25.2.0,在我的情况下,gradle显示我并且错误:

  

所有com.android.support库必须使用完全相同的版本   规范(混合版本可能导致运行时崩溃)。发现   版本25.2.0,25.0.0。例子包括   com.android.support:animated-vector-drawable:25.2.0和   com.android.support:customtabs:25.0.0

要解决此问题,我必须添加此行compile 'com.android.support:customtabs:25.2.0',强制将此版本用于customtabs。

<强>之前:

//    android support
    compile 'com.android.support:recyclerview-v7:25.2.0'
    compile 'com.android.support:cardview-v7:25.2.0'
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:design:25.2.0'

<强>后:

//    android support
    compile 'com.android.support:recyclerview-v7:25.2.0'
    compile 'com.android.support:customtabs:25.2.0'
    compile 'com.android.support:cardview-v7:25.2.0'
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:design:25.2.0'

如果您遇到这样的错误,我建议您添加显示所需版本错误的库。

相关问题