Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add recycle view in layout xml

I am following this link, as mentioned in the link I am trying to add recycle view as follows:

 <android.support.v7.widget.RecyclerView
 android:id="@+id/my_recycler_view"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:scrollbars="vertical" />

I have added android-support-v7-appcompat library project and also tried adding recyclerview-v7-21.0.0-rc1.aar to libs but still I am getting following error.

The following classes could not be found: - android.support.v7.widget.RecyclerView

Note: I have updated Android SDK Tools, Android SDK Platform Tools, Android SDK Build Tools, Android L (API 20, L Preview)

please help..

like image 223
DCoder Avatar asked Sep 29 '14 07:09

DCoder


2 Answers

You can't add the aar file to libs folder in Eclipse (it isn't a jar file)

The best way to work with the new RecyclerView is, currently, to switch to Android Studio and add this dependency to your build.gradle

compile 'com.android.support:recyclerview-v7:+'

Just a note. It is not a good practice to use the '+' placeholder, but in this case you are trying a preview release, so it will be update soon with stable release.

You can use one of these versions. Check your sdk for updated version:

  //it requires compileSdkVersion 23
  compile 'com.android.support:recyclerview-v7:23.3.0'
  compile 'com.android.support:recyclerview-v7:23.2.1'
  compile 'com.android.support:recyclerview-v7:23.2.0'
  compile 'com.android.support:recyclerview-v7:23.1.1'
  compile 'com.android.support:recyclerview-v7:23.1.0'
  compile 'com.android.support:recyclerview-v7:23.0.1'
  compile 'com.android.support:recyclerview-v7:23.0.0'

  //it requires compileSdkVersion 22
  compile 'com.android.support:recyclerview-v7:22.2.1'
  compile 'com.android.support:recyclerview-v7:22.2.0'
  compile 'com.android.support:recyclerview-v7:22.1.1'
  compile 'com.android.support:recyclerview-v7:22.1.0'
  compile 'com.android.support:recyclerview-v7:22.0.0'

  //it requires compileSdkVersion 21
  compile 'com.android.support:recyclerview-v7:21.0.3'
  compile 'com.android.support:recyclerview-v7:21.0.2'
  compile 'com.android.support:recyclerview-v7:21.0.0'

Of course you can still use Eclipse but it will requires some manual operations.
You can find all the release of the support libraries library in this folder:

sdk/extras/android/m2repository/com/android/support/

Here you can check all version.
In the folders you will find the aar file of the support libraries. Inside you can check the classes.jar file,the res folder and the AndroidManifest file.

  • Create a project in your workspace

  • Unzip the AAR into some directory.

  • Copy the AndroidManifest.xml, the res, and assets folders from the AAR into your project.

  • Create a libs directory in your project and copy into it the classes.jar

  • Add the dependency.

  • Use the SDK 23 to compile

  • Mark the project as a library

The Recyclerview library has the support-v4.jar and the support-annotations-23.x.X.jar as dependencies.

like image 124
Gabriele Mariotti Avatar answered Oct 21 '22 15:10

Gabriele Mariotti


ECLIPSE

If your problem is not solved or for future readers , here is the answer: From android sdk manager download Android Support Library first.

Go to this location and copy .aar file from here

X:\android-sdk\extras\android\m2repository\com\android\support\recyclerview-v7\21.0.0

Then rename it as .zip file then unZIP it then find classes.jar file , rename it with some proper name like 'RecyclerView_v7.jar' Then copy the that .jar file in you project library. Add it to build path then restart eclipse so that it can be instantiated (not necessary but i had to do this).

          **=================================Update=======================**

After new Library Updates; RecyclerView,CardView etc are available as simple library projects.! :)

File~>Import~>Existing Android Code~>SDKpath~>extras~>android~>support~> v7~>recyclerView.

Then right click on this project , go to properties under Android check Is Library. It is done ..!

Now open your app in which you want to use recyclerView. goto properties of your app Project under Android add Library here you will find that Library project add that (remember don't make your app a library project by checking 'Is Library'), now go to your App Project's

Properties~>Java Build Path~>Libraries~>Add Jars~>RecyclerView LibraryProject~>libs

Then add that jar into your project and buildpath .! Pheeew.. :)

like image 3
mfaisalhyder Avatar answered Oct 21 '22 15:10

mfaisalhyder