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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.