Skip to content

Instantly share code, notes, and snippets.

@FrantisekGazo
Last active March 15, 2016 21:54
Show Gist options
  • Save FrantisekGazo/eeba9cbc4e3d4f65cee4 to your computer and use it in GitHub Desktop.
Save FrantisekGazo/eeba9cbc4e3d4f65cee4 to your computer and use it in GitHub Desktop.
Simple RecyclerAdapter. Best used with MVP module of Blade library (https://github.com/FrantisekGazo/Blade)
package eu.f3rog.ui.adapter;
import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;
/**
* Class {@link RecyclerAdapter}
*
* @author FrantisekGazo
* @version 2016-02-27
*/
public final class RecyclerAdapter<T>
extends RecyclerView.Adapter<MyRecyclerAdapter.ViewHolder> {
public static final class ViewHolder
extends RecyclerView.ViewHolder {
public ViewHolder(View itemView) {
super(itemView);
}
}
private LayoutInflater mLayoutInflater;
private List<T> mItems;
@LayoutRes
private final int mLayout;
public MyRecyclerAdapter(@NonNull Context c, @NonNull List<T> items, @LayoutRes int layout) {
mLayoutInflater = LayoutInflater.from(c);
mItems = items;
mLayout = layout;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ViewHolder(mLayoutInflater.inflate(mLayout, parent, false));
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.itemView.setTag(mItems.get(position));
}
@Override
public int getItemCount() {
return (mItems != null) ? mItems.size() : 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment