Closed MrNegativeTW closed 4 years ago
在 LiveCamFragment 中,使用 RecyclerView 列出可用相機列表,並於 onClick 後更新 UI 上元件
onClick
Repository
MutableLiveData
onDestory
observe
新增 Repository ?
LiveCamFragment.kt:56 LiveCamSelectCardAdapter.kt:16
LiveCamFragment.kt:56
LiveCamSelectCardAdapter.kt:16
How can I refresh viewModel livedata from another activity
Seems solved by adding inner in front of that ViewHolder
inner
ViewHolder
Details
Context
在 LiveCamFragment 中,使用 RecyclerView 列出可用相機列表,並於
onClick
後更新 UI 上元件The Problem
Repository
作為橋梁,ViewModel 與 Adapter 間資料無法互通MutableLiveData
,就算 ViewModelonDestory
後,資料仍繼續存在,下次進入時將會讀取上次資訊。Solution For Now
MutableLiveData
,並在onClick
時更新observe
並更新相對應 UIWhat I want
新增 Repository ?
Problem Code Location
LiveCamFragment.kt:56
LiveCamSelectCardAdapter.kt:16
Reference
How can I refresh viewModel livedata from another activity