Niels
Niels

Reputation: 669

Android - SwipeRefreshLayout import not found

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.

Upvotes: 18

Views: 22213

Answers (8)

Amaan Ahmad
Amaan Ahmad

Reputation: 25

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.

Upvotes: 0

harry
harry

Reputation: 261

latest lib is

implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

then sync the project

Upvotes: 1

Sohrab Gharavi
Sohrab Gharavi

Reputation: 41

just add this into yourbuld gradle module dependencies:

implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"

Upvotes: 3

Ashok Kumar Yadav
Ashok Kumar Yadav

Reputation: 61

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'

Upvotes: 6

李李楠
李李楠

Reputation: 41

Try this in built.gradle:

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

In *.java:

import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

Upvotes: 4

murgupluoglu
murgupluoglu

Reputation: 7205

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'

Upvotes: 43

kalidoss rajendran
kalidoss rajendran

Reputation: 640

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.

Upvotes: 1

Rajesh
Rajesh

Reputation: 291

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.

Upvotes: 14

Related Questions