March 2013
Beginner to intermediate
580 pages
16h 11m
English
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, ...Read now
Unlock full access