17

I'm trying to implement the new RefreshLayout widget but it seems my eclipse doesn't recognize the import I need to set. I used this guide to get started: Swipe to refresh GUIDE

And here is where it all started: Android dev - Swipe to refresh

My first guess was that I need to update my project in some way to get the latest android API's? I've never done that before and I don't even know that possible.

If anyone could lead me into the right direction to solve this problem that would be great.

The import line:

import android.support.v4.widget.SwipeRefreshLayout;

Manifest:

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="19" />

After updating the libraries to latest versions the import is still not recognized.

Niels
  • 659
  • 2
  • 7
  • 15
  • 1
    [Here's Google's guide on setting up the support library](https://developer.android.com/tools/support-library/setup.html) – adneal Apr 03 '14 at 18:00

8 Answers8

39

If you are using Material Library version 1.2.0 (like com.google.android.material:material:1.2.0-alpha03) , than you must import swipe refresh layout library too.

   implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
murgupluoglu
  • 6,524
  • 4
  • 33
  • 43
14

To use SwipeRefreshLayout make sure you have updated Android Support Library. To check if it is updated follow below steps:

--> Open Eclipse

--> Go to Window-> Android SDK Manager.

--> In SDK Manager scroll down to bottom. Look for Android Support Library. If rev. is 19.1 then you are good to use SwipeRefreshLayout. If it is less than 19.1, then update Androd Support Library.

--> Once it is updated you can use SwipeRefreshLayout for new project. But you still cannot use SwipeRefreshLayout for existing projects.

Below are the steps to use SwipeRefreshLayout in existing project.

--> After updating Android Support Library, create new project.

--> Look for android-support-v4.jar in this project.

--> Copy android-support-v4.jar from new project and replace android-support-v4.jar of existing project with new project's android-support-v4.jar.

--> Now you can use SwipeRefreshLayout in existing project as well.

Rajesh
  • 291
  • 3
  • 6
  • 3
    No need to create a new project and copy the lib from there. Just go to `/extras/android/support/v4/` and copy it from there. – Enrichman May 21 '14 at 20:11
  • Of if you have the ADT plugin installed, just remove the old support lib, and right click the project -> Android tools -> Add support Library – BratAnon Aug 16 '14 at 10:04
5

This is what worked for me...

If you are using google Material Library version 1.2.0 (like com.google.android.material:material:1.3.0-alpha01) , than you have to explicitly import swipe refresh layout library too.

implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
VVN
  • 1,607
  • 2
  • 16
  • 25
4

Try this in built.gradle:

implementation 'androidx.legacy:legacy-support-v4:1.0.0'

In *.java:

import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
Azametzin
  • 5,223
  • 12
  • 28
  • 46
李李楠
  • 41
  • 1
3

just add this into yourbuld gradle module dependencies:

implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
1

The SDK Manager update Android Support Library to 19.1.0. But when you use Android Tools > Add Support Library, eclipse update Android Support Library to 19.0. I think this is a bug. Copy Android Support Library 19.1.0 to libs folder manually.

1

latest lib is

implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

then sync the project

harry
  • 171
  • 1
  • 4
0

To fix this error, you need to add the androidx.swiperefreshlayout.widget library to your project. You can do this by following these steps:

Open your project in Android Studio. In the Project window, right-click on the app module and select Open Module Settings. In the Module Settings dialog, select the Dependencies tab. Click the + button and select Add Library dependency. In the Library Dependency dialog, select the AndroidX library and then select the androidx.swiperefreshlayout.widget library. Click the OK button. Once you have added the androidx.swiperefreshlayout.widget library to your project, the error message should go away.