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​>​ ...

Get Android Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.