2

Following up on my previous question about importing a certain library from github in my project, I decided I wanted to implement a different one, but I get lots of errors at this point.

Importing Android Listview refresh by pull, project-properties error

In line with Google currently using Chris Banes' ActionBar-PullToRefresh: https://github.com/chrisbanes/ActionBar-PullToRefresh, I've decided I wanted to used that library as well for the Android app that I'm currently developing for my internship. When I try to import the existing code into the workspace from the unpacked zip-file though, I instantly get a ton of errors, in the library as well as in the example activities. For instance, in the library folder, in ActionBarPullToRefresh.java, it underlines Class within the first private hashmap and says references to the generic type Class should be parameterized.

The IDE (eclipse) also gives tons of errors to the other folders included, and when I add the library folder to the libraries of my main project, using the properties -> android tab, it carries over the errors to that project (quite logically).

Could anyone send me into a direction as to how I should successfully import and use this library?

Community
  • 1
  • 1
Dennis450D
  • 62
  • 1
  • 7

3 Answers3

4

I will write this here for future PullToRefresh users. I use IntelliJ IDEA instead of eclipse, so remember that the word Module and Project are equivalent. When you have to add a project to Eclipse, the action is add module in IDEA.

Example with ActionBarSherlock (ABS from now).

What you have:

  1. You have a Module named: MyProject. This is your main Android module.
  2. You want to add PullToRefresh to a few Fragments (for example) in your MyProject.

Step One: Download and Copy.

I personally like to have a clone or fork of the libraries I'm using to read the commits and change logs. Not only you learn by seeing other people's code, but also you get the "latest news" about the libraries you use. It's a win-win situation. Remember what Jeff Atwood said: "Read The Source, Luke". So in order to do this, Clone ActionBar-PullToRefresh from the right URL.

Now I don't like having the clone with my modules/projects so I usually clone projects somewhere else and later manually move what I need. It's tedious but that way I only get what I want. So what do you need then? The clone contains two important directories: Extras and Library. We're going to need stuff from these.

Copy the library directory to your project root: /path/to/your/project/pulltorefresh Copy the corresponding (ABS or Compat) extra to your project root as well…

This is what you got so far:

/path/to/your/project/MyProject
/path/to/your/project/pulltorefresh
/path/to/your/project/pulltorefresh-abs (or compat)

Step Two Import these: Import these modules (projects in eclipse) into the project/workspace. This should be simple if you know your IDE, but as a quick reference: File -> Import Module -> find the pulltorefresh folder from above (and the -abs or compat later) and follow the wizard. If you're using Eclipse, check this link to know how to do it.

Now you should have in your left panel (⌘1) the following structure

MyProject
pulltorefresh
pulltorefresh-abs

Step 3 Add the right references

Assuming MyProject has actiobnarsherlock.jar (because you need it) or the corresponding android support library for compat and that you have the corresponding android-support-v13 (or v4) as well…

  1. pulltorefresh doesn't need any library reference.
  2. pulltorefresh-abs needs a reference to: pulltorefresh, android-suppport-vX and actiobbarsherlock
  3. MyProject needs a reference to: pulltorefresh-abs, android-suport-vX and actiobbarsherlock

Of course both android-support and actiobarsherlock could sit in MyProject and be exported (and taken from there) by the other libraries, but that's project management 101 ;)

Step 4 Integrate! This is easier, just follow the Quick Start Guide. REMEMBER: in older versions of the lib you had to have an attacher in an Activity, that is no longer necessary. Read the documentation, it's very simple (and much more flexible this way).

Wait, What If You Don't Use Either Sherlock or Compat??

I haven't done this yet, but my guess is:

  1. Don't import -abs or -compat in extras. Just import pulltorefresh.
  2. From your project, reference pulltorefresh.

Hold on… what about imports?!

Getting the right imports is important for any library, you have to pay attention and not blindly let your IDE do it for you (or at least always double check what you're importing). You'd be surprised to see how many "name collisions" are out there.

For Action Bar Sherlock based projects, the imports should be:

import uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshLayout;
import uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh;
import uk.co.senab.actionbarpulltorefresh.library.listeners.OnRefreshListener;

For a non sherlock pure project:

import uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh;
import uk.co.senab.actionbarpulltorefresh.library.listeners.OnRefreshListener;
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout;

Where did you get those?!?!?!?!

By looking at the samples, Luke.

For example, here's for the stock version.

The final step would be to profit… but I leave that up to you ;)

If you still have an issue, the guys are friendly provided you don't ask lazy questions. Feel free to follow the project and participate in the issues page at github.

Good Luck refreshing!

Community
  • 1
  • 1
Martin Marconcini
  • 26,875
  • 19
  • 106
  • 144
  • Thank you very much for your detailed response. I'll try this out asap and will let you know if I succeed – Dennis450D Dec 11 '13 at 19:48
  • Sorry if this a really obvious question, but I was wondering if it's still normal to, after a reference has been created to pulltorefresh (originally the library class) and it's been included in the builpath, still have an error around the private hashmap in the very top of ActionBarPulltoRefresh.java . I'm not sure where my errors are coming from, but the library is full of them in my Eclipse – Dennis450D Dec 11 '13 at 20:32
  • What version are you using? (of the library) I'm using 0.9.2 (and I know there's a 0.93 but haven't upgraded yet. And what is the exact line of the error? – Martin Marconcini Dec 11 '13 at 20:43
  • `private HashMap mViewDelegates;` ? – Martin Marconcini Dec 11 '13 at 20:46
  • It says: "Class is a raw type. References to generic type Class should be parameterized" – Dennis450D Dec 11 '13 at 20:58
  • I think I'm seeing one of the potential problems. For some reasons the MainActivity is trying to retrieve a parent for an item, but the folder is my downloads folder where the library is originally extracted in. "Users/dennis/Downloads/ActionBar-PullToRefresh-master/library/res/values/styles.xml:19: error: Error retrieving parent for item: No resource found that matches the given name 'SmoothProgressBar'." Could this have anything to do with the project setup? – Dennis450D Dec 11 '13 at 21:18
  • Seems like you're using the latest version (0.9.3)? They added SmoothProgressBar in this release. Specifically in this commit: https://github.com/chrisbanes/ActionBar-PullToRefresh/commit/3ffd268a0aee679ce4bc4dd47d125f223d970fd3 I'm not sure if this is a problem with the current lib. Maybe you should go to their Github Issues and ask there: https://github.com/chrisbanes/ActionBar-PullToRefresh/issues?direction=desc&sort=updated&state=open Like I said, I'm using 0.9.2 still so I don't know if this will be a problem yet. :p – Martin Marconcini Dec 11 '13 at 22:10
  • It could be something with the setup, but it's hard for me to tell because I don't have the latest version, don't have Eclipse and above all, I use Sherlock and you don't. :/ – Martin Marconcini Dec 11 '13 at 22:12
  • @MartínMarconcini It is a problem. Going to try using `0.9.2` with your instructions. – theblang Jan 15 '14 at 18:02
  • 0.9.2 works with these instructions. I switched from Sherlock to ActionBarCompat yesterday and it still works. 0.9.3 is more problematic because of smoothprogressbar, I couldn't get that working because I don't have Gradle and you have to mess with importing stuff that is Gradle/Maven optimized. Problem is, Android Studio is tooooo buggy at the moment. Especially for "med-large" projects. – Martin Marconcini Jan 15 '14 at 18:52
  • @MartínMarconcini Yup, `0.9.2` works great! Thanks for the instructions! I completely agree about `Studio`. I really wanted to use it, but it's just not ready yet. Also, setting this up made me realize the benefits of something like Maven / Gradle. – theblang Jan 15 '14 at 19:21
  • Gradle is awesome (when it works) but Android Studio doesn't let you mix regular modules with gradle libraries (yet) and importing regular libraries is bugged in the latest version… it will get better, I hope. In the mean time, the pain is that most libraries ONLY release instructions to import via Gradle (which is good!) but a pain at this time :) – Martin Marconcini Jan 15 '14 at 20:40
3

I don't use Gradle myself, but we all should, as it is a quantum leap for build technology in the Java (JVM) world (from Gradle introduction). This is how to reference projects libraries for PTR v 0.9.3:

  1. Your project has to reference PullToRefresh aka PTR
  2. PTR has to reference SmoothProgressBar aka SPB, which you can find here, on github
  3. Both PTR and SPB should be Android libraries, so make sure that checkbox is checked (Properties -> Android -> IsLibrary)
  4. The "tricky" part: Once you have cloned SPB on your local machine copy the contents of SmoothProgressBar\library\src\main\java into SmoothProgressBar\library\src\main\src (that is the structure ADT expects)
  5. remember to add the support library to SPB if you target lower that 14

Assuming you know how to reference an android library project in eclipse (if not, google it), that is all about you need to do.

Good luck! :)

  • Thank you for your answer. Fortunately, I was able to resolve my issues through the discussion on the project-page on Github. I forgot to flag Martín's comment as answered, my apologies. – Dennis450D Jan 21 '14 at 20:19
  • This is good info, because PTR 0.9.3> uses SmoothProgressBar (whereas 0.9.2, the version I am using, doesn't). So you have to keep this in mind :) – Martin Marconcini Feb 27 '14 at 23:02
1

Non-senior developers/git users might find the following link useful (like I did) http://www.rahuljiresal.com/2014/04/actionbar-pull-to-refresh-on-android/

rahuljiresal has created a git project that contains both Chris Banes' Actionbar-PullToRefresh AND the referencing SmoothProgressBar all in one: https://github.com/rahuljiresal/ActionBar-PullToRefresh

The steps described above by Martin i.e.
1. Download/ Clone git project locally
2. Import PTR library into Eclipse
3. Reference PTR library from your project
4. Integrate

are still valid, but the whole process is incredibly easier and plug-and-play.

Community
  • 1
  • 1
kouretinho
  • 2,190
  • 1
  • 23
  • 37