Reputation: 12919
I'd like to use the new CardView widget that was introduced with the new Android L Developer Preview Support Library (As mentioned here), which seems to be part of a new revision of the v7 support library.
I have now updated my SDK version, downloaded the newest Support Library package, but I still cannot find the new CardView widget.
I already searched the web and the official docs, but could not get any hints on where I can get the new support library.
Any help is highly appreciated!
EDIT: I'm using ADT/Eclipse
Upvotes: 62
Views: 161475
Reputation: 420
In the most latest android, we implement card view like this:
build.gradle file:
dependencies {
...
compile 'com.android.support:cardview-v7:24.0.0'
}
and in the xml file its referenced as:
<androidx.cardview.widget.CardView
…>
…
</androidx.cardview.widget.CardView>
this means its class has changed to:
androidx.cardview.widget.CardView
Upvotes: 0
Reputation: 595
I was able to work it out only after adding those two TOGETHER:
dependencies {
...
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
...
}
in my build.gradle (Module:app) file
and then press the sync now button
Upvotes: 10
Reputation: 1006984
Using Gradle or Android Studio, try adding a dependency on com.android.support:cardview-v7
.
There does not seem to be a regular Android library project at this time for cardview-v7
, leanback-v17
, palette-v7
, or recyclerview-v7
. I have no idea if/when Google will ship such library projects.
Upvotes: 52
Reputation: 1039
Simply add the following line in your build.gradle
project
dependencies {
...
compile 'com.android.support:cardview-v7:24.0.0'
}
And sync the project with gradle.
Upvotes: 2
Reputation: 1097
Maybe it's a little bit late to add answer here. But I think this answer will help the later ones and especially those who don't want to use Android Studio.
Although the documents says that RecyclerView and CardView are part of v7 appcompat library. But as I tried and found, RecyclerView and CardView are actually depend on v7 appcompat library. So if you want to use RecyclerView or CardView, you need to add both v7 appcompat library and RecyclerView/CardView.
Referencing the link here, if you want to use CardView in your Eclipse android project, you need to import both v7 appcompat library and CardView into Eclipse workspace and make them as library projects. Then make CardView project depends on v7 appcompat library project and make your project depends on CardView project.
Upvotes: 2
Reputation: 1112
From: https://developer.android.com/tools/support-library/setup.html#libs-with-res
Adding libraries with resources To add a Support Library with resources (such as v7 appcompat for action bar) to your application project:
Using Eclipse
Create a library project based on the support library code:
Make sure you have downloaded the Android Support Library using the SDK Manager.
Create a library project and ensure the required JAR files are included in the project's build path:
Select File > Import.
Select Existing Android Code Into Workspace and click Next.
Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the appcompat project, browse to /extras/android/support/v7/appcompat/.
Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
In the new library project, expand the libs/ folder, right-click each .jar file and select Build
Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both the android-support-v4.jar and android-support-v7-appcompat.jar files to the build path.
Right-click the library project folder and select Build Path > Configure Build Path.
In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.
Uncheck Android Dependencies.
Click OK to complete the changes.
You now have a library project for your selected Support Library that you can use with one or more application projects.
Add the library to your application project:
In the Project Explorer, right-click your project and select Properties.
In the category panel on the left side of the dialog, select Android.
In the Library pane, click the Add button.
Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-appcompat.
In the properties window, click OK.
Upvotes: 2
Reputation: 1445
Although a bit hidden it's in the official docs here where can the library be found among the sdk's code, and how to get it with resources (the Eclipse way)
Upvotes: 3
Reputation: 12919
I finally found a way to use CardView in ADT/Eclipse. It's actually pretty easy:
android.support.v7.cardview
exploded-aar
folder in Android Studio and copy the following files to these locations:
Adding libraries with resources
here: https://developer.android.com/tools/support-library/setup.htmlAs an alternative to having to create a new Android Studio project in order to get the AAR's content, you could also simply find and unzip the AAR from the local maven repo. Just follow the steps provided by Andrew Chen below.
Please note the CardView library might not be available in source- and ADT-compatible-form because it's still only a preview and a WIP. As there might be bug fixes and improvements in following releases, it's important to keep the library up-to-date, which is easy using the Gradle dependency, but must be done manually when using the steps provided above.
Upvotes: 41
Reputation: 676
I have done following and it resolve an issue with recyclerview same you may use for other widget as well if it's not working in eclipse project.
• Go to sdk\extras\android\m2repository\com\android\support\recyclerview-v7\21.0.0-rc1 directory
• Copy recyclerview-v7-21.0.0-rc1.aar file and rename it as .zip
• Unzip the file, you will get classes.jar (rename the jar file more meaningful name)
• Use the following jar in your project build path or lib directory.
and it resolve your error.
happy coding :)
Upvotes: 27
Reputation: 447
https://github.com/yongjhih/CardView
A CardView v7 eclipse project. (from sdk/extras/android/m2repository/com/android/support/cardview-v7)
The project was built by steps:
cp {sdk}/extras/android/m2repository/com/android/support/cardview-v7/21.0.0-rc1/cardview-v7-21.0.0-rc1.aar cardview-v7-21.0.0-rc1.zip
unzip cardview-v7-21.0.0-rc1.zip
mkdir libs/
mv classes.jar libs/cardview-v7-21.0.0-rc1.jar
Upvotes: 19
Reputation: 2028
I did what FD_ said and it crashed with errors as it was looking for "Landroid/support/v7/cardview/R$styleable;", which was not compiled with it
If you really want to use CardView before in eclipse before it gets its own library, you can extract the classes from the classes.jar, copy and paste them into your project, with the values.xml from above from Android Studio and change all the references to android.support.v7.R to yourpackagename.R in the copied classes. This worked and ran for me
Upvotes: 0