2017-03-08 18 views
0

我最近對Android Studio 2.3進行了升級,而沒有找到getAdapterPosition(RecyclerView)。我在網上看到,原因是支持庫版本。但我不確定如何解決它。我的支持:appcompat-v7:25.2.0'版本是最新的(例如21以上)。我不明白爲什麼找不到方法。有什麼建議嗎?找不到getAdapterPosition()作爲方法

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:[email protected]') { // 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' 
+0

getLayoutPosition()在類中這個方法是更好的選擇,讓項目的位置。如果您找不到解決方案 –

回答

3

你可以檢查你在ViewHolder類中使用這種方法嗎?

getAdapterPostion()RecyclerView.ViewHolder的方法。

你需要確保你使用的擴展RecyclerView.ViewHolder

+0

就這麼簡單:D我在ViewHolder類之外使用它。非常感謝您指出了這一點! :) –

1

請添加此依賴性: 編譯 'com.android.support:recyclerview-v7:23.3.0'

+0

感謝您的建議,您可以嘗試使用此功能。但是,它沒有擺脫錯誤:/ –

1

也許你不得不使用buildToolsVersion 25.2.0過了,在我的情況下gradle這個給我和錯誤:

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 25.2.0, 25.0.0. Examples include com.android.support:animated-vector-drawable:25.2.0 and 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' 

如果你有一個這樣的錯誤,我建議你補充一點,說明你想要的版本錯誤的庫。

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

可能會丟失該行?

+0

我嘗試過。情況並非如此。還是)感謝你的建議! :) –