Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个带有切换按钮的列表(项目数量不确定)。每次我按下后退按钮并再次进入该页面时,所有切换按钮都会在 xml 中变为关闭状态。我怎样才能得到切换按钮的位置和“setChecked”呢?或任何检查我之前检查过的切换按钮的方法(设置为 ON)
用于onPause()保存切换按钮的状态:
onPause()
bundle.putBoolean("ToggleButtonState", toggleButton.isChecked());
用于onResume()检索切换按钮的状态:
onResume()
toggleButton.setChecked(bundle.getBoolean("ToggleButtonState",false));