Skip to content

Instantly share code, notes, and snippets.

@matdziu
Created November 17, 2016 11:04
Show Gist options
  • Select an option

  • Save matdziu/dae745dfd607b2adde1bf1e19f675192 to your computer and use it in GitHub Desktop.

Select an option

Save matdziu/dae745dfd607b2adde1bf1e19f675192 to your computer and use it in GitHub Desktop.
public class ViewHolderFactory {
public static class ButtonViewHolder extends RecyclerView.ViewHolder {
public Button button;
public ButtonViewHolder(View itemView) {
super(itemView);
button = (Button) itemView.findViewById(R.id.button);
}
}
public static class TextViewHolder extends RecyclerView.ViewHolder {
public TextView headerTextView;
public TextView textView1;
public TextViewHolder(View itemView) {
super(itemView);
headerTextView = (TextView) itemView.findViewById(R.id.header_text);
textView1 = (TextView) itemView.findViewById(R.id.text_view1);
}
}
public static class ImageViewHolder extends RecyclerView.ViewHolder {
public ImageView imageView;
public TextView textView2;
public ImageViewHolder(View itemView) {
super(itemView);
imageView = (ImageView) itemView.findViewById(R.id.image_view);
textView2 = (TextView) itemView.findViewById(R.id.text_view2);
}
}
public static RecyclerView.ViewHolder create(ViewGroup parent, int viewType) {
switch (viewType) {
case RowType.BUTTON_ROW_TYPE:
View buttonTypeView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_type_button, parent, false);
return new ViewHolderFactory.ButtonViewHolder(buttonTypeView);
case RowType.TEXT_ROW_TYPE:
View textTypeView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_type_text, parent, false);
return new ViewHolderFactory.TextViewHolder(textTypeView);
case RowType.IMAGE_ROW_TYPE:
View imageTypeView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_type_image, parent, false);
return new ViewHolderFactory.ImageViewHolder(imageTypeView);
default:
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment