0

It's been a while I'm trying to run/code a RecyclerView example, with no success though. I guess it has something to do with the RecyclerView version used in dependencies and the Android versions my project is using. Currently, I'm trying to run this example here.

It doesn't mention what are the compileSdkVersion, minSdkVersion and so on. Anyway, here's my gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.deluxe.example"
        minSdkVersion 24
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0-rc01'
    implementation 'com.squareup.picasso:picasso:2.5.2'
}

Also in this example, the Adapter imports android.support.v7.widget.RecyclerView, for which I get an error: Cannot resolve symbol v7. So, Android suggested importing androidx.recyclerview.widget.RecyclerView;

Issue: my project doesn't load the RecyclerView in the MainActivity - it throws an exception: Error inflating class android.support.v7.widget.RecyclerView for which although there're similar questions here and here and here, I couldn't solve my issue.

I'm new to Android Studio, so can anyone suggest what should I change in order to run this Recycler/CardView example? I've tried several examples already, but wasn't able to run any of them - recent and older ones. I'm trying to run using Android Nougat(7.0) and upper, but it's not mandatory. And my Android Studio version is 3.5.1

Mac122
  • 25
  • 1
  • 3

1 Answers1

1

Because you're using Androidx (good), then you need to import the corresponding artifacts:

implementation 'androidx.recyclerview:recyclerview:1.1.0-beta04' (or whatever latest version exists)

And then in all the places where you reference RecyclerView, (hint: use Android studio "find" and search for the term recyclerview to find and evaluate all references and places where it's mentioned), and ensure you are referencing the new artifacts, e.g.:

import androidx.recyclerview.widget.RecyclerView in code and

<androidx.recyclerview.widget.RecyclerView ... in XML.

While you are at it, remove

    implementation 'com.android.support:recyclerview-v7:28.0.0-rc01'

And if you can, replace:

    implementation 'com.android.support:cardview-v7:28.0.0'

with:

    implementation "com.google.android.material:material:1.1.0-alpha10"

And use:

 <com.google.android.material.card.MaterialCardView 

in your XMLs.

Martin Marconcini
  • 26,875
  • 19
  • 106
  • 144
  • 1
    Thanks, I changed accordingly, and I was able to see the layout at least. Couldn;t run the app though.. I got different errors which I believe are related to another issue. – Mac122 Oct 07 '19 at 02:04