Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't Android Studio resolve symbol ViewPager?

I'm new to Android and I'm following the Big Nerd Ranch Guide. In the book we are creating a ViewPager to be able to swipe between list-details. For some reason Android Studio doesn't recognise the ViewPager. Look below for the code.

import android.app.Activity;
import android.os.Bundle;
import android.view.ViewPager;

public class CrimePagerActivity extends Activity {
    private ViewPager mViewPager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
}

I don't know what to do or what could be wrong? Has this something to do with the Android SDK?

like image 406
user3065567 Avatar asked Sep 11 '15 21:09

user3065567


People also ask

Is ViewPager deprecated?

This function is deprecated.

How do I use ViewPager on Android?

Android ViewPager widget is found in the support library and it allows the user to swipe left or right to see an entirely new screen. Today we're implementing a ViewPager by using Views and PagerAdapter. Though we can implement the same using Fragments too, but we'll discuss that in a later tutorial.

What is ViewPager adapter?

ViewPager in Android is a class that allows the user to flip left and right through pages of data. This class provides the functionality to flip pages in app. It is a widget found in the support library. To use it you'll have to put the element inside your XML layout file that'll contain multiple child views.


Video Answer


1 Answers

Make sure you have downloaded the Android Support Repository using the SDK Manager.

Open the build.gradle file and Add the support library to the dependencies section:

compile 'com.android.support:support-v4:23.0.1'

change your import to this:

import android.support.v4.view.ViewPager;
like image 78
Milad Nouri Avatar answered Oct 13 '22 00:10

Milad Nouri