0

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:

enter image description here

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 :-)

4

1 回答 1

1

我发现了问题所在:它是 DAO 中的接收类。如果模型类被扩展,超类的附加字段必须设置为列信息或获取@Ignore标签,否则它们是不完整的Room实体,扩展类将无法接收Room查询。

AbstractItem 虽然是一个库类并且是只读的。因此,我将内容复制到具有不同名称(“MyAbstractItem”fi)的类中,并将@Ignore 标记放在附加字段上。房间停止抱怨。

不知道有没有更优雅的解决方案,你知道吗?

编辑:这里的好答案:

Android Room:是否可以在实体中使用有界类型参数?

于 2018-09-01T22:02:17.117 回答