SugarORM:SugarRecord.count返回4,但是SugarRecord.listAll返回空列表 [英] SugarORM: SugarRecord.count returns 4 but SugarRecord.listAll returns empty list

查看:100
本文介绍了SugarORM:SugarRecord.count返回4,但是SugarRecord.listAll返回空列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在模型中使用@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返回空列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆