I currently have
public class MyRecycler extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
private List<SectionOrRow> mData;
public MyRecycler(List<SectionOrRow> data) {
mData = data;
}
...
@Override
public int getItemCount() {
return mData.size();
}
...
}
and need to pass a list of objects using
SectionOrRow.createRow("row x");
or
SectionOrRow.createSection("section x");
however I do not know where or how to construct this list. Adding it so that the code becomes
public Adapter(List<SectionOrRow> data) {
SectionOrRow.createRow("row 1");
SectionOrRow.createSection("section 1");
mData = data;
}
gives the following error:
Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
Inferring, this sounds like my mData has size is null, as the error occurs on the line that returns the mData size; so obviously adding it inside that class is incorrect. What is the correct way to construct the list?
Edit 1: SectionOrRow class:
public class SectionOrRow {
private String row;
private String section;
private boolean isRow;
public static SectionOrRow createRow(String row) {
SectionOrRow ret = new SectionOrRow();
ret.row = row;
ret.isRow = true;
return ret;
}
public static SectionOrRow createSection(String section) {
SectionOrRow ret = new SectionOrRow();
ret.section = section;
ret.isRow = false;
return ret;
}
public String getRow() {
return row;
}
public String getSection() {
return section;
}
public boolean isRow() {
return isRow;
}
}