[코틀린] LiveData

LiveData

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()
})