无法在Android架构组件1.1.1中找到类DiffCallback:

时间:2018-04-01 08:37:50

标签: android android-gradle android-architecture-components android-architecture-lifecycle

最近我在gradle文件中更新了android.arch支持库版本

 // ViewModel and LiveData
    implementation "android.arch.lifecycle:extensions:1.1.1"

    // alternatively, just ViewModel
    implementation "android.arch.lifecycle:viewmodel:1.1.1"

    // alternatively, just LiveData
    implementation "android.arch.lifecycle:livedata:1.1.1"
    annotationProcessor "android.arch.lifecycle:compiler:1.1.1"

    // Room (use 1.1.0-alpha1 for latest alpha)
    implementation "android.arch.persistence.room:runtime:1.0.0"
    annotationProcessor "android.arch.persistence.room:compiler:1.0.0"

    // Paging
    implementation "android.arch.paging:runtime:1.0.0-alpha7"

现在我声明收到此错误

enter image description here

2 个答案:

答案 0 :(得分:14)

使用DiffUtil.ItemCallback类:

 public static final DiffUtil.ItemCallback<User> DIFF_CALLBACK =
             new DiffUtil.ItemCallback<User>() {
     @Override
     public boolean areItemsTheSame(
             @NonNull User oldUser, @NonNull User newUser) {
             //..
     }
     @Override
     public boolean areContentsTheSame(
             @NonNull User oldUser, @NonNull User newUser) {
         //..
     }
 }

您还可以查看DiffCallback课程。现在,此课程已移至recyclerview-v7已弃用

答案 1 :(得分:1)

不确定您之前使用的版本,但来自changelog ( 1.0.0-alpha6, February 27, 2018)

  

重命名了类,并将其移至recyclerview-v7:

     
      
  • DiffCallback - &gt; DiffUtil.ItemCallback
  •