Everytime i add new item to database using Livedata, it is retriving all data from database. But i want only the latest updated item to display on the screen when i click save button
Here is the Code
MAIN ACTIVITY
viewModel.retrieveItem(idd).observe(this , Observer{
selectedItem = it
if(selectedItem != null){
entry = selectedItem as Entry
bind(entry)
}else{
blank()
}
private fun bind(entry: Entry){
editText.setText(entry.diaryEntry,TextView.BufferType.SPANNABLE)
}
VIEW MODEL
fun retrieveItem(id: Int): LiveData<Entry> {
return diaryDao.getItem(id)
}
DAO
@Query("SELECT * from diary WHERE id = :id")
fun getItem(id: Int): LiveData<Entry>
Any help would be Appreciated