Skip to content

Instantly share code, notes, and snippets.

View ziginsider's full-sized avatar
🤴
καὶ σύ, τέκνον

Aliaksei ziginsider

🤴
καὶ σύ, τέκνον
View GitHub Profile
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);
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
app:cardElevation="10dp">
<LinearLayout
android:layout_width="match_parent"
public class ButtonRowType implements RowType {
private Context context;
public ButtonRowType(Context context) {
this.context = context;
}
public View.OnClickListener getOnClickListener() {
return new View.OnClickListener() {
public class ImageRowType implements RowType {
private String text;
public ImageRowType(String text) {
this.text = text;
}
public String getText() {
return text;
public class TextRowType implements RowType {
private String header;
private String text;
public TextRowType(String header, String text) {
this.header = header;
this.text = text;
}
public interface RowType {
int BUTTON_ROW_TYPE = 0;
int IMAGE_ROW_TYPE = 1;
int TEXT_ROW_TYPE = 2;
}
public class MultipleTypesAdapter extends RecyclerView.Adapter {
private List<RowType> dataSet;
public MultipleTypesAdapter(List<RowType> dataSet) {
this.dataSet = dataSet;
}
@Override
public int getItemViewType(int position) {
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);
}
@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);
}
public class MultipleTypesAdapter extends RecyclerView.Adapter {
private List<RowType> dataSet;
public MultipleTypesAdapter(List<RowType> dataSet) {
this.dataSet = dataSet;
}
@Override
public int getItemViewType(int position) {