【发布时间】:2015-09-14 12:09:31
【问题描述】:
我刚开始使用 Realm 库,并试图在我的 android 应用程序中实现它。刚刚卡在我试图根据我的 json 响应 中特定元素的视图类型来划分我的 listview 的地方。
我尝试使用 recycler view 实现这些部分,但问题是我有 2 种视图类型,并且为这些视图类型添加标题会导致问题。由于 Realm 没有 RecyclerAdapter 的支持,我创建了一个实现,它将使用支持 RecyclerView 的自定义适配器。
所以,虽然我将使用ListView 并尝试为每个对象类型使用一个简单的接口来确定类型,然后根据组的位置插入标题。
由于某种原因,Realm 不允许我在扩展 RealmObject 的类中实现接口。
这就是那个类的样子:
import com.google.gson.annotations.SerializedName;
import io.realm.RealmObject;
import io.realm.annotations.Ignore;
import io.realm.annotations.PrimaryKey;
public class TestClass extends RealmObject implements Subjects {
@PrimaryKey
@SerializedName("subjectID")
private String subjectID;
private String subjectDate;
@SerializedName("subjectDescription")
private String subjectDescription;
public String getSubjectID() {
return subjectID;
}
public void setSubjectID(String subjectID) {
this.subjectID = subjectID;
}
public String getSubjectDate() {
return subjectDate;
}
public void setSubjectDate(String subjectDate) {
this.subjectDate = subjectDate;
}
public String getSubjectDescription() {
return subjectDescription;
}
public void setSubjectDescription(String subjectDescription) {
this.subjectDescription = subjectDescription;
}
@Override
public boolean isSubjectA() {
return true;
}
@Override
public boolean isFoo() {
return false;
}
@Override
public boolean isBar() {
return false;
}
}
这是编译错误日志:
Error:(76, 20) error: Getter isSubject is not associated to any field.
Note: Creating DefaultRealmModule
Warning:File for type 'io.realm.DefaultRealmModule' created in the last round will not be subject to annotation processing.
Warning:File for type 'io.realm.DefaultRealmModuleMediator' created in the last round will not be subject to annotation processing.
2 warnings
我不知道为什么抱怨这个问题,但它没有编译项目。
我在这里阅读了一些关于这个问题的讨论:link .. 显然,有一个关于这个问题的公开讨论,但任何其他帮助将非常感激.. 谢谢
【问题讨论】:
-
我猜它假设 isSubject 应该寻找一个主题属性。你可以试试 isIsSubject 吗?
-
嗯..如果它可以工作会很奇怪,但我会试一试。
-
未按预期工作,但不确定实际原因可能是什么。 . :(
-
我认为 Banabastard 的回答很有道理。
-
它只是一个错字.. 这只是一个实现的测试示例。我的坏
标签: java android listview android-recyclerview realm