Android media viewer recyclerview adapter

Introduction

The android media viewer recyclerview adapter tutorial series describes how to create the adapter which will provide the mediastore thumbnail images to the recyclerview.

This tutorial will just describe creating the bare implementation of the RecyclerView adapter.

Get Code

The code can be found on github from the following instructions below

https://github.com/mobapptuts/media-thumbnail-viewer.git Tag

media-viewer-adapter

or you can run this command

git clone https://github.com/mobapptuts/media-thumbnail-viewer.git –branch

media-viewer-adapter

This video describes how to import a project from github using android studio and also how get use the git tags.

Steps

Add the RecyclerView dependency to the build.gradle file

build.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:recyclerview-v7:23.4.0'
}

Create a new RelativeLayout to hold the ImageView

media_image_view.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:layout_width="128dp"
        android:layout_height="128dp"
        android:id="@+id/mediastoreImageView"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

Create the recyclerview adapter and setup a ViewHolder

MediaStoreAdapter

public class MediaStoreAdapter extends RecyclerView.Adapter<MediaStoreAdapter.ViewHolder> {

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.media_image_view, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

    }

    @Override
    public int getItemCount() {
        return 0;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        private final ImageView mImageView;

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

            mImageView = (ImageView) itemView.findViewById(R.id.mediastoreImageView);
        }

        public ImageView getImageView() {
            return mImageView;
        }
    }
}

 

Android media viewer recyclerview adapter summary

Part 2 of the android media thumbnail viewer tutorial series describes how to create a RecyclerView adapter. The above example provides the standard implementation of the adapter.

The following tutorial will describe how to process the MediaStore cursor and therefore how to load thumbnail bitmaps from MediaStore images & videos.

About The Author
-

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>