Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

android - How to call function after updating data in room persistence library

This is my function inside viewModel class:

fun updateMenu(menu: Menu) = viewModelScope.launch {
    menuDao.update(menu) // updating menu to database
    total = hitungTotal() // calculate all subtotal to total
}

private fun hitungTotal(): Int {
    var sum = 0
    menuList.value?.apply {
        for (i in this.indices) sum += this.get(i).subTotal
    }
    return sum
}

I want hitungTotal() function to be executed after the database is updated. How to achieve this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...