From AsyncTask Back to the Main Thread

To finish off, let’s switch to the view layer and get PhotoGalleryFragment’s RecyclerView to display some captions.

First define a ViewHolder as an inner class.

Listing 25.14  Adding a ViewHolder implementation (PhotoGalleryFragment.java)

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        ...
    }

    private class PhotoHolder extends RecyclerView.ViewHolder {
        private TextView mTitleTextView;

        public PhotoHolder(View itemView) {
            super(itemView);

            mTitleTextView = (TextView) itemView;
        }

        public void bindGalleryItem(GalleryItem item) {
            mTitleTextView.setText(item.toString());
        }
    } private class FetchItemsTask extends AsyncTask<Void,Void,Void> ...

Get Android Programming: The Big Nerd Ranch Guide, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.