Created
June 21, 2020 19:59
-
-
Save codejunk1e/dbd6e8e53ca56051402b49d9d5b3a836 to your computer and use it in GitHub Desktop.
RecyclerView file template for Android
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
#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 androidx.annotation.NonNull; | |
import androidx.recyclerview.widget.RecyclerView; | |
import java.util.List; | |
#parse("File Header.java") | |
public class ${NAME} extends RecyclerView.Adapter<${NAME}.ViewHolder> { | |
private final Context context; | |
private List<${ITEM_CLASS}> items; | |
public ${NAME}(List<${ITEM_CLASS}> items, Context context) { | |
this.items = items; | |
this.context = context; | |
} | |
@NonNull | |
@Override | |
public ${NAME}.ViewHolder onCreateViewHolder( | |
ViewGroup parent, | |
int viewType) { | |
View v = LayoutInflater.from(parent.getContext()) | |
.inflate(R.layout.${LAYOUT}, parent, false); | |
return new ${NAME}.ViewHolder(v); | |
} | |
@Override | |
public void onBindViewHolder(@NonNull ${NAME}.ViewHolder holder, int position) { | |
${ITEM_CLASS} item = items.get(position); | |
} | |
@Override | |
public int getItemCount() { | |
if (items == null){ | |
return 0; | |
} | |
return items.size(); | |
} | |
public class ViewHolder extends RecyclerView.ViewHolder { | |
public ViewHolder(@NonNull View itemView) { | |
super(itemView); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment