Last active
March 15, 2016 21:54
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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