Search code examples
androidandroid-recyclerviewandroidxandroid-jetifier

RecyclerView ItemDecoration broken with AndroidX


I have a compiler issue when using DividerItemDecoration with a RecyclerView in an existing project we are updating to use AndroidX libraries.

The project unfortunately uses DataBinding, which may be part of the issue. We have some ugly code like this:

getBinding().myRecyclerField.addItemDecoration(new DividerItemDecoration(...));

Which tells me

enter image description here

AS automatically adds the AndroidX import for the class and the android.support.v7.widget.DividerItemDecoration no longer seems to be available.

How should ItemDecorations be used with RecyclerViews now?

Do we need to manually replace the RecyclerView tag in every layout? (This has not been necessary for other views (eg toolbars)


Solution

  • Eventually to solve this I did have to replace all usages of RecyclerView with the androidx.recyclerview package and ensuring that I have android.enableJetifier=true and android.useAndroidX=true in my gradle properties to make the libraries compatible

    Support/Default RecyclerView and AndroidX RecyclerView components cannot be mixed