Bog'liq Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019
QuizDao.kt under the
data > db package. Take a look at
getAllQuestions()
and
getQuestionAndAllAnswers()
:
@Query("SELECT * FROM question ORDER BY question_id")
fun
getAllQuestions
()
: List
@Transaction
@Query("SELECT * FROM question")
fun
getQuestionAndAllAnswers
()
: List Right now, these methods are just returning a simple
List
but how do you make
them return a LiveData object instead? Well, it's actually very easy! You just need to
change your method signatures to this:
@Query("SELECT * FROM question ORDER BY question_id")
fun
getAllQuestions
()
: LiveData>
@Transaction
@Query("SELECT * FROM question")
fun
getQuestionAndAllAnswers
()
:
LiveData>
Note: Don't forget to import all missing dependencies using