Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A recylerview adapter template
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;
public class ${NAME} extends RecyclerView.Adapter<${NAME}.${VIEWHOLDER_CLASS}> {
private final Context context;
private List<${ITEM_CLASS}> itemList;
public ${NAME}(List<${ITEM_CLASS}> itemList, Context context) {
this.itemList = itemList;
this.context = context;
public ${VIEWHOLDER_CLASS} onCreateViewHolder(ViewGroup parent,
int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.${LAYOUT_RES_ID}, parent, false);
return new ${VIEWHOLDER_CLASS}(v);
public void onBindViewHolder(${VIEWHOLDER_CLASS} holder, int position) {
${ITEM_CLASS} item = itemList.get(position);
//TODO Implement here
public int getItemCount() {
if (itemList == null){
return 0;
return itemList.size();
class ${VIEWHOLDER_CLASS} extends RecyclerView.ViewHolder {
public ${VIEWHOLDER_CLASS}(View itemView) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment