我想根據我的資料庫更改一個名為“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()
})
}
請我需要一個有用的答案,感謝您的耐心等待
uj5u.com熱心網友回復:
您需要執行更新查詢。將 ROOM 用于 SQLITE,您可以在 DAO 類上創建更新查詢,您可以呼叫 RestaurantDao。在那里分配所有查詢,例如更新、洗掉、插入等。
示例:(根據你的表結構修改表和變數的名稱。
@Query("UPDATE my_restaurant_table SET value=:value "
"WHERE id=:id"
) public abstract void updateRestaurant(
long id,
String value
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/404537.html
標籤:
上一篇:單擊卡片視圖時如何導航到片段
