问题
I use the @Table
annotation for my model and call SugarRecord.save
in a DialogFragment.setPositiveButton.onClick
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.
My Code
Syllable.java
@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
}
回答1:
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
来源:https://stackoverflow.com/questions/37521271/sugarorm-sugarrecord-count-returns-4-but-sugarrecord-listall-returns-empty-list