greendao的使用增删改查<3>

greendao的增删改查

public class MainActivity extends AppCompatActivity {
    private NoteDao noteDao;
    private Note note;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        DaoSession daoSession = ((AppApplication) getApplication()).getDaoSession();
        noteDao = daoSession.getNoteDao();

        addNote();
        queryNote();
        updateNote();
        deleteNote();
    }

    public void addNote() {
        note = new Note();
        note.setText("this is test note!");
        note.setComment("this is comment");
        noteDao.insert(note);
        Log.d("DaoExample", "Inserted new note, ID: " + note.getId());
    }

    public void deleteNote() {
        noteDao.delete(note);
    }

    public void updateNote() {
        note.setText("this is after modify note!");
        noteDao.update(note);
    }

    public void queryNote() {
       List<Note> noteList = noteDao.queryBuilder().where(NoteDao.Properties.Text.eq("this is after modify note!")).build().list();
    }

}

使用stetho查看数据库
android调试桥工具stetho的使用

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,984评论 25 709
  • 框架:提供一定能力的小段程序 http://www.cnblogs.com/jincheng-yangchaofa...
    姑娘请别为难小僧阅读 12,093评论 0 132
  • 一.榜单介绍 排行榜包括四大类: 单一框架:仅提供路由、网络层、UI层、通信层或其他单一功能的框架 混合开发框架:...
    伟子男阅读 10,610评论 0 161
  • 迎着落日,她和他慢慢地走。枯黄的芦苇,空荡荡的枝叶,在此时也别有一番韵味。她想,就在这余晖里,一起慢慢走向前,那未...
    风夏_d97d阅读 2,523评论 0 0