Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1
Preparing RecyclerView to Display Images

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

Free download pdf