O'Reilly logo

Android Programming: The Big Nerd Ranch Guide, Third Edition by Kristin Marsicano, Chris Stewart, Bill Phillips

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required