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:
- You have a Module named: MyProject. This is your main Android module.
- 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…
- pulltorefresh doesn't need any library reference.
- pulltorefresh-abs needs a reference to:
pulltorefresh
, android-suppport-vX
and actiobbarsherlock
- 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:
- Don't import -abs or -compat in
extras
. Just import pulltorefresh
.
- 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!