【发布时间】:2026-01-07 10:30:01
【问题描述】:
在屏幕旋转时,选定的项目被取消选择,我想保存它的状态。 我在 recyclerView 中有所有这些表单,点击时会被选中。这是 onListItemClick 中的代码
private void onListItemClick(View view, int position) {
Cursor cursor = instanceAdapter.getCursor();
cursor.moveToPosition(position);
CheckBox checkBox = view.findViewById(R.id.checkbox);
checkBox.setChecked(!checkBox.isChecked());
long id = cursor.getLong(cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns._ID));
if (selectedInstances.contains(id)) {
selectedInstances.remove(id);
} else {
selectedInstances.add(id);
}
Bundle bundle=new Bundle();
sendButton.setEnabled(selectedInstances.size() > 0);
toggleButtonLabel();
}
其中 selectedInstances 是 LinkedHashSet
private LinkedHashSet<Long> selectedInstances;
这是动图
【问题讨论】:
标签: android android-recyclerview android-checkbox screen-rotation linkedhashset