Chapter 25 HTTP and Background Tasks
Now that you have such fine JSON from Flickr, what should you do with it? You do what you do with
all data – put it in one or more model objects. The model class you are going to create for PhotoGallery
is called GalleryItem. Figure 25.10 shows an object diagram of PhotoGallery.
Figure 25.10 Object diagram of PhotoGallery
Note that Figure 25.10 does not show the hosting activity so that it can focus on the fragment and the
networking code.
Create the GalleryItem class and add the following code:
Listing 25.10 Creating model object class (GalleryItem.java)
public class GalleryItem {
private String mCaption;
private String mId;
private String mUrl;
@Override
public String toString() {
return mCaption;
}
}
Have Android Studio generate getters and setters for mCaption, mId, and mUrl.
Now that you have made model objects, it is time to fill them with data from the JSON you got from
Flickr.