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)

public class PhotoGalleryFragment extends Fragment {
    private static final String TAG = "PhotoGalleryFragment";

    GridView mGridView;
    ArrayList<GalleryItem> mItems; ... @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_photo_gallery, ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.