O'Reilly logo

Android Programming: The Big Nerd Ranch Guide by Brian Hardy, Bill Phillips

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

From AsyncTask Back to the Main Thread

To finish off, let’s return to the view layer and get PhotoGalleryFragment’s GridView to display some captions.

GridView is an AdapterView, like ListView, so it needs an adapter to feed it views to display.

In PhotoGalleryFragment.java, add an ArrayList of GalleryItems and then set up an ArrayAdapter that uses a simple layout provided by Android.

Listing 26.13  Implement setupAdapter() (PhotoGalleryFragment.java)

p​u​b​l​i​c​ ​c​l​a​s​s​ ​P​h​o​t​o​G​a​l​l​e​r​y​F​r​a​g​m​e​n​t​ ​e​x​t​e​n​d​s​ ​F​r​a​g​m​e​n​t​ ​{​
 ​ ​ ​ ​p​r​i​v​a​t​e​ ​s​t​a​t​i​c​ ​f​i​n​a​l​ ​S​t​r​i​n​g​ ​T​A​G​ ​=​ ​"​P​h​o​t​o​G​a​l​l​e​r​y​F​r​a​g​m​e​n​t​"​;​

 ​ ​ ​ ​G​r​i​d​V​i​e​w​ ​m​G​r​i​d​V​i​e​w​;​
 ​ ​ ​ ​A​r​r​a​y​L​i​s​t​<​G​a​l​l​e​r​y​I​t​e​m​>​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required