This file contains hidden or 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
public interface RowType { | |
int BUTTON_ROW_TYPE = 0; | |
int IMAGE_ROW_TYPE = 1; | |
int TEXT_ROW_TYPE = 2; | |
int getItemViewType(); | |
void onBindViewHolder(RecyclerView.ViewHolder viewHolder); | |
} |
This file contains hidden or 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
public class ImageRowType implements RowType { | |
private String text; | |
public ImageRowType(String text) { | |
this.text = text; | |
} | |
public String getText() { | |
return text; |
This file contains hidden or 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
public class TextRowType implements RowType { | |
private String header; | |
private String text; | |
public TextRowType(String header, String text) { | |
this.header = header; | |
this.text = text; | |
} |
This file contains hidden or 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
public interface RowType { | |
int BUTTON_ROW_TYPE = 0; | |
int IMAGE_ROW_TYPE = 1; | |
int TEXT_ROW_TYPE = 2; | |
} |
This file contains hidden or 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
public class MultipleTypesAdapter extends RecyclerView.Adapter { | |
private List<RowType> dataSet; | |
public MultipleTypesAdapter(List<RowType> dataSet) { | |
this.dataSet = dataSet; | |
} | |
@Override | |
public int getItemViewType(int position) { |
This file contains hidden or 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
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); | |
} |
This file contains hidden or 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
@Override | |
public int getItemViewType() { | |
return RowType.TEXT_ROW_TYPE; | |
} | |
@Override | |
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder) { | |
ViewHolderFactory.TextViewHolder textViewHolder = (ViewHolderFactory.TextViewHolder) viewHolder; | |
textViewHolder.headerTextView.setText(header); | |
textViewHolder.textView1.setText(text); | |
} |
This file contains hidden or 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
public class MultipleTypesAdapter extends RecyclerView.Adapter { | |
private List<RowType> dataSet; | |
public MultipleTypesAdapter(List<RowType> dataSet) { | |
this.dataSet = dataSet; | |
} | |
@Override | |
public int getItemViewType(int position) { |
OlderNewer