Skip to content

Instantly share code, notes, and snippets.

@riggaroo
Created May 2, 2016 16:12
Show Gist options
  • Save riggaroo/6db62da4ffbced347be5a217aea6a0e9 to your computer and use it in GitHub Desktop.
Save riggaroo/6db62da4ffbced347be5a217aea6a0e9 to your computer and use it in GitHub Desktop.
File Template for Android Studio for creating a RecyclerViewAdapter without having to remember much of the boilerplate.
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;
#parse("File Header.java")
public class ${NAME} extends RecyclerView.Adapter<${VIEWHOLDER_CLASS}> {
private final Context context;
private List<${ITEM_CLASS}> items;
public ${NAME}(List<${ITEM_CLASS}> items, Context context) {
this.items = items;
this.context = context;
}
@Override
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);
}
@Override
public void onBindViewHolder(${VIEWHOLDER_CLASS} holder, int position) {
${ITEM_CLASS} item = items.get(position);
//TODO Fill in your logic for binding the view.
}
@Override
public int getItemCount() {
if (items == null){
return 0;
}
return items.size();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment