I am trying to use Mike Penz Fastadapter. According to the ReadMe, the first step is to have a model class that extends "AbstractItem" from his library. I did that on my Room entity class, because that is the item that I want to have in the recyclerview:
@Entity(tableName = "Category")
public class Cat extends AbstractItem<Cat, Cat.ViewHolder> {
@PrimaryKey
@NonNull
@ColumnInfo(name = "CID")
public String uid;
public String getID() { return this.uid; }
@ColumnInfo(name = "HeadID")
public String iHeaduid;
//...various getters and setters...
public Cat() {}
public Cat(String sNameP, int iCatLevelP, Cat oHeadCatP)
{
this.uid = UUID.randomUUID().toString();
this.sName = sNameP;
this.oSubCatList = new ArrayList<Cat>();
this.iCatLevel = iCatLevelP;
this.oHeadCat = oHeadCatP;
if (this.oHeadCat != null) {
this.sHeadName = oHeadCatP.sName;
this.iHeaduid = oHeadCatP.uid;
}
else
this.sHeadName = null;
}
// Methods that implement AbstractItem - I already set them on ignore...
@Ignore
@Override
public int getType() {
return R.id.textViewCat;
}
@Ignore
@Override
public int getLayoutRes() {
return R.layout.catrecyclerview_item;
}
@Ignore
@Override
public void bindView(ViewHolder holder) {
super.bindView(holder);
}
protected static class ViewHolder extends RecyclerView.ViewHolder{
protected TextView oTextView;
public ViewHolder(View itemView) {
super(itemView);
oTextView = itemView.findViewById(R.id.textViewCat);
}
}
}
My entity that used to work just fine now throws compile errors:
It seems like there are issues when using Room on extended entities, as suggested by this related question. This is quite a bummer, since Fastadapter would have been a nice solution for N-level expandables. Any idea on how to tackle this problem? Can I use Room with Fastadaper?
I could copy the list of items into a non-database dummy model class, but that seems quite inefficient to me and would add bloat code to synchronise the database with the dummy...
Ideas appreciated :-)