Dean Blakely
Dean Blakely

Reputation: 3585

How to use Android ViewPager

I'm planning a port of some apps from Windows Phone 7 over to Android. Going through some blogs I find an "extra" android control called the ViewPager which seems like a poor man's version of the WP7 Pivot control. I would like to try using this control since my WP7 apps use the Pivot.

I plan on targeting Android 2.3.3 (API 10) because the info at http://developer.android.com/resources/dashboard/platform-versions.html tells me that any level higher would run on relatively few phones. So, my Eclipse is setup for that level.

Using the Eclipse SDK manager I tried to add the Extras Android support package but it would not add giving the errors pasted below. I don't know what all those errors mean but I'm wondering if I need to be running API 11 to be able to use the compatibiity package aka the android Support Package?

So, I suppose my final question is: can I use the VeiwPager control if I target Android 2.3.3? Also, is there any downloadable complete solution that uses the viewPager? All I can find are "tutorials" that show code snippets. Thanks, Dean

Preparing to install archives
Downloading Android SDK Platform-tools, revision 11
File not found: C:\Program Files (x86)\Android\android-sdk\temp\platform-tools_r11-windows.zip (Access is denied)
Downloading Documentation for Android SDK, API 15, revision 2
File not found: C:\Program Files (x86)\Android\android-sdk\temp\docs-15_r02.zip (Access is denied)
Downloading SDK Platform Android 4.0.3, API 15, revision 3
File not found: C:\Program Files (x86)\Android\android-sdk\temp\android-15_r03.zip (Access is denied)
Downloading Samples for SDK API 15, revision 2
File not found: C:\Program Files (x86)\Android\android-sdk\temp\samples-15_r02.zip (Access is denied)
Downloading ARM EABI v7a System Image, Android API 15, revision 2
File not found: C:\Program Files (x86)\Android\android-sdk\temp\sysimg_armv7a-15_r02.zip (Access is denied)
Downloading Sources for Android SDK, API 15, revision 2
File not found: C:\Program Files (x86)\Android\android-sdk\temp\sources-15_r02.zip (Access is denied)
Downloading Android Support package, revision 8
File not found: C:\Program Files (x86)\Android\android-sdk\temp\support_r08.zip (Access is denied)
Skipping 'Android SDK Tools, revision 19'; it depends on 'Android SDK Platform-tools, revision 11' which was not installed.
Done. Nothing was installed.

Upvotes: 3

Views: 10192

Answers (2)

Sparky
Sparky

Reputation: 8477

To elaborate on Mark's point a little: in your AndroidManifest.xml, you should put this line:

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />

Where 15 may be replaced by whatever is the newest API level at the time you compile, and 8 is the lowest API level you want to run on. As of this writing, API level 8 (Froyo) and higher will let you target about 94% of the device population.

The Android Support Package (V4) lets you call a bunch of useful functions all the way back to API level 4, including ViewPager. Try building the Suport4Demos sample app; it includes a nice ViewPager implementation. To do that, in Eclipse, select: New > Android Sample Project > Android 4.0.3 > Support4Demos > Finish. Then build & run the project.

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006604

I'm wondering if I need to be running API 11 to be able to use the compatibiity package aka the android Support Package?

No.

can I use the VeiwPager control if I target Android 2.3.3?

Yes.

Also, is there any downloadable complete solution that uses the viewPager?

Here is a small sample app showing 10 EditText widgets, one per page, in a ViewPager.

Here is a more complex app, implementing a digital book reader, with one chapter (in a WebView) per page in a ViewPager, but it might not make much sense outside the context of one of my books.

With respect to your errors, my guess is that you installed the Android SDK via the self-installing .EXE file, in which case you will need to run the SDK Manager with Administrator privileges to update it, IIRC.

Upvotes: 7

Related Questions