Instantly share code, notes, and snippets.

Embed
What would you like to do?
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