Android Programming The Big Nerd Ranch Guide, 3rd Edition

(Brent) #1
Preparing RecyclerView to Display Images

501

Update PhotoAdapter’s onBindViewHolder(...) to set the placeholder image as the ImageView’s
Drawable.


Listing 26.3  Binding default image (PhotoGalleryFragment.java)


public class PhotoGalleryFragment extends Fragment {
...
private class PhotoAdapter extends RecyclerView.Adapter {
...
@Override
public void onBindViewHolder(PhotoHolder photoHolder, int position) {
GalleryItem galleryItem = mGalleryItems.get(position);
photoHolder.bindGalleryItem(galleryItem);
Drawable placeholder = getResources().getDrawable(R.drawable.bill_up_close);
photoHolder.bindDrawable(placeholder);
}
...
}
...
}


Run PhotoGallery, and you should see an array of close-up Bills, as in Figure 26.2.


Figure 26.2  A Billsplosion


http://www.ebook3000.com

Free download pdf