I used a small hack to use the RecyclerView on older devices. I just went into my local m2 repository and picked up the RecyclerView source files and put them into my project.
A great way to import the RecyclerView into your project is the RecyclerViewLib. This is an open source library which pulled out the RecyclerView to make it safe and easy implement. You can read the author's blog post here.
Add the following line as a gradle dependency in your code:
More info for how to bring in gradle dependencies:
Bosnia you're right about that being annoying. Gradle may seem complicated but it is extremely powerful and flexible. Everything is done in the language groovy and learning the gradle system is learning another language just so you can build your Android app. It hurts now, but in the long run you'll love it.
Pay attention to the location of this file. This is not the top level build.gradle
Because the lib source is in the same project it is able to do this with the simple ':library'. The exclude tells the lib to use the sample app's support v4. That isn't necessary but is a good idea. You don't have or want to have the lib's source in your project, so you have to point to the internet for it. In your module's/app's build.gradle you would put that line from the beginning of this answer in the same location. Or, if following the samples example, you could replace ':library' with ' com.twotoasters.RecyclerViewLib:library:1.0.+@aar ' and use the excludes.
in my case I fixed it by putting compile 'com.android.support:recyclerview-v7:22.0.0' as a dependency into my gradle build
(with Android studio v. 1.2.1.1 and all sdk's updated.)
It's really annoying when codes are updated so fast and the IDE can't keep track of them, and you have to manually fix for them, wasting time and resources.
If You have Compiled SDK Version 22.2.0 then add below dependency for recycler view and cardview additional for support of cardView
// for including all the libarary in the directory lib compile fileTree(include: ['*.jar'], dir: 'libs')
// for support appcompat compile 'com.android.support:appcompat-v7:22.2.0'
//for including google support design (it makes possible of implementing material design theme from 2.3 and higher)
`compile 'com.android.support:design:22.2.0'
for adding the recycler view use following dependency
compile 'com.android.support:recyclerview-v7:22.2.0'
After that click on Build->rebuild project and you are done.
-Go to the DESIGN part in activity_main.xml
-In the drag drop pallet select appCompactivity
-In appCompactivity Select RecyclerView
-On Selection a dialog shall appear click OK
-Your project app:gradle will automatically get updated
I used this one is working for me. One thing needs to be consider that what appcompat version you are using. I am using appcompat-v7:26.+ so this is working for me.
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.0'
//RecyclerView dependency
compile 'com.android.support:recyclerview-v7:25.1.0'
// Instrumentation dependencies use androidTestCompile
// (as opposed to testCompile for local unit tests run in the JVM)
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:25.1.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
}
I added only compile 'com.android.support:recyclerview-v7:25.1.0'. The important thing is to add RecycleView dependency which is as the same version as appcompat
Also all com.android.support libraries must use the exact same version specification; in addition, support libraries such as appcompat-v7 and recyclerview-v7 should not use a different version than the compileSdkVersion.
If you using the updated or 2018 Version for Android Studio...
compile 'com.android.support:recyclerview-v7:+'
will give you an error with following message
"Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018."