[코틀린] LiveData
LiveData
- The observable data holder class
Add dependency
// ViewModel
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
Get liveData
@Dao
interface TodoDao {
@Query("SELECT * FROM Todo")
fun getAll(): LiveData<List<Todo>>
...
}
Observe data & action
db.todoDao.getAll().observe(this, Observer{
todos->result_text.text = todos.toString()
})