Cant find class DiffCallback in Android Architecture component 1.1.1:
R

2

9

Recently I updated android.arch support library version in gradle file

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

Now I stated getting this error

enter image description here

Ribwort answered 1/4, 2018 at 8:37 Comment(0)
T
16

Use the DiffUtil.ItemCallback class:

 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) {
         //..
     }
 }

You can also check the DiffCallback class. Now this class is moved in recyclerview-v7 and it is deprecated.

Tarrance answered 1/4, 2018 at 9:0 Comment(1)
I'm not getting latest DiffUtil class although I updated RecyclerView by adding implementation 'com.android.support:recyclerview-v7:27.1.1'. Any idea what is the issue?@GabrieleMariottiReinsure
F
1

Not sure which version you were using earlier, but from the changelog ( 1.0.0-alpha6, February 27, 2018),

Classes renamed, and moved to recyclerview-v7:

  • DiffCallback -> DiffUtil.ItemCallback
Farrica answered 1/4, 2018 at 9:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.