我有一個有listview的應用程序。列表視圖中的每個視圖都具有自定義xml並具有按鈕複選框和文本視圖。我必須從sqlite數據庫中獲取以前保存的複選框設置並設置它們。如果用戶更改複選框或單選按鈕,我必須將這些設置保存在數據庫中。在列表視圖中更新信息的設計
嘗試了幾種不同的方式來做到這一點,大多數導致錯誤,並且在返回頁面時不會顯示覆選框的正確設置。
終於工作的是以下所示的設計。在那裏我把任何數據庫調用盡可能靠近實際視圖。然而,它看起來像是在列表視圖中有很多行,它會對數據庫進行多次調用,並且可能會變慢。
是我設計的正確或是否有更好的辦法
psudocode
onCreate
instantiate arraylist adapter and set adapter to view
end onCreate
arrayadapter class
getView(){
call databsase and get previous settings for checkboxes in this view and
set the checkboxes to show checked or not depending on database saved settings
onClicklistener or oncheckedchanged listener for getting checkbox positions if changed
call database and set method to store updated positions of checkbox, radiobutton or spinner
}
end arrayadapter