13.12 保存到 Realm 中

新增待办事项,存入Realm数据库:

  1. private fun createTodoFrom(title: EditText, todoContent: EditText) {
  2. realm.beginTransaction()
  3. // Either update the edited object or create a new one.
  4. var t = todo ?: realm.createObject(Todo::class.java)
  5. t.id = todo?.id ?: UUID.randomUUID().toString()
  6. t.title = title.text.toString()
  7. t.content = todoContent.text.toString()
  8. realm.commitTransaction()
  9. activity.supportFragmentManager.popBackStack()
  10. }