问题描述
我在模型中使用@Table
批注,并在DialogFragment.setPositiveButton.onClick
I use the @Table
annotation for my model and call SugarRecord.save
in a DialogFragment.setPositiveButton.onClick
在具有ListView的片段中,我想通过SugarRecord.listAll
加载所有条目,但是尽管SugarRecord.count
返回正确的计数,但它返回一个空列表.
In the Fragment with the ListView I wanted to load all entries via SugarRecord.listAll
but it returns an empty list, although SugarRecord.count
returns the proper count.
@Table
@ToString
@Getter
public class Syllable {
private Long id;
@Unique
String characters;
@Setter
boolean active = true;
public Syllable(String characters) {
this.characters = characters;
}
}
DialogFragment.setPositiveButton
.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
SugarRecord.save(new Syllable(charactersET.getText().toString()));
syllableDialogListener.onSyllableSave();
}
})
Fragment.onSyllableSave
private void updateSyllables() {
long count = SugarRecord.count(Syllable.class); // returns 4 (e.g.)
List<Syllable> syllables = SugarRecord.listAll(Syllable.class); // returns empty list
}
推荐答案
好,我只是在模型上缺少一个空的构造函数> _>问题是这不是在android中真正打印为红色错误样式的错误工作室,所以我只是想念这个; D
OK, I was just missing an empty constructor at the model >_> Problem was this wasn't really printed as an red-error-style error in android studio so I just missed this ;D
这篇关于SugarORM:SugarRecord.count返回4,但是SugarRecord.listAll返回空列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!