I have a RecyclerView that works and everything, and this is how I coded it:
public class RazzleRecyclerViewAdapter extends RecyclerView.Adapter<RazzleRecyclerViewAdapter.RecyclerViewHolder> {
private List<Razzle> mRazzleList;
private Context mContext;
private SelectRazzleRowListener mSelectRazzleRowListener;
public RazzleRecyclerViewAdapter(
Context context,
List<Razzle> razzleList,
SelectRazzleRowListener selectRazzleRowListener) {
mContext = context;
mRazzleList = razzleList;
mSelectRazzleRowListener = selectRazzleRowListener;
}
@Override
public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new RecyclerViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_razzle_row, parent, false));
}
@Override
public void onBindViewHolder(RecyclerViewHolder holder, int position) {
holder.bindRow(mRazzleList.get(position), position);
}
@Override
public int getItemCount() {
return mRazzleList.size();
}
public class RecyclerViewHolder extends RecyclerView.ViewHolder {
public int thisPosition;
public Razzle mThisRazzle;
public TextView razzleNameTextView;
public RecyclerViewHolder(View itemView) {
super(itemView);
razzleNameTextView = (TextView) itemView.findViewById(R.id.item_razzle_row_textview_razzle_name);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mSelectRazzleRowListener.launchRazzleDetailsActivity(mThisRazzle, thisPosition);
}
});
}
public void bindRow(final Razzle razzle, int position) {
mThisRazzle = razzle;
thisPosition = position;
razzleNameTextView.setText(razzle.getRazzleName());
}
}
}
How can I code this better? Can I make it clearer? Am I following good conventions? Can I restructure it so it's easier to work with? In particular, the ViewHolder stuff?