DAO
@Query("SELECT COUNT(category) FROM todolist_table")
fun getAllTaskCount() : LiveData<Int>
Repo
suspend fun getAllTaskCount() : LiveData<Int> {
return todoDao.getAllTaskCount()
}
ViewModel
fun getAllTaskCount(){
viewModelScope.launch(Dispatchers.IO) {
repository.getAllTaskCount()
}
}
View
val viewModel = ToDoViewModel(application = LocalContext.current.applicationContext as Application)
val taskCount = viewModel.getAllTaskCounter()
I want to take count of categories from database but it's returning null