RecyclerView ItemDecoration broken with AndroidX

929 Views Asked by At

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)

2

There are 2 best solutions below

0
On BEST ANSWER

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

0
On

Use always Refractor > Migrate to AndroidX, that will convert all imports, uses automatically.

It will add android.enableJetifier=true and android.useAndroidX=true too.

Useful Post