【发布时间】:2022-01-18 21:46:21
【问题描述】:
我想根据我的数据库更改一个名为“value”的变量的值,它代表屏幕中显示的值,这是我的代码
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val mViewModel = ViewModelProvider(this).get(ExpenseCalculatorViewModel::class.java)
binding.categoryName.text = args.category
val viewModel = ViewModelProvider(this).get(CategoriesViewModel::class.java)
when (binding.categoryName.text) {
getString(R.string.restaurant) -> {
viewModel.readRestaurantData.observe(viewLifecycleOwner, {
var value = 0
for (i in it.indices) {
value += it[i].restaurant
}
binding.totalNumber.text = value.toString()
})
}
我需要一个有用的答案,感谢您的耐心等待
【问题讨论】:
-
您能否澄清更改后的值会发生什么?你想在屏幕上显示还是保存在数据库中?
标签: database android-studio kotlin android-fragments android-room