【发布时间】:2014-12-25 14:59:30
【问题描述】:
每次选中或取消选中复选框时,我都遇到了添加/删除已添加到 ArrayList 的字符串的问题。
问题似乎是在选中超过1个复选框时换字符串复制。因此,如果我要检查第一个框,它会将其添加到数组中。如果我取消选中第一个框,它将从数组中删除它。当我做第二个复选框时,问题就出现了。当我按下另一个复选框时,它似乎添加了先前的复选框字符串,而不是其当前字符串的 2 个。
Only the first checkbox checked
10-29 14:46:10.051: E/PAGES(14154): [alertPage]
2 checkboxes checked
10-29 14:46:10.051: E/PAGES(14154): [alertPage, alertPage, automationPage]
这种模式会持续到每个额外的复选框
关于为什么会发生这种情况的任何想法?
强文本
if (mCheckBoxAlerts.isChecked()) {
mAlertsPermLayout.setVisibility(LinearLayout.VISIBLE);
pageArray.add("alertPage");
} else {
mAlertsPermLayout.setVisibility(LinearLayout.GONE);
pageArray.remove("alertPage");
}
if (mCheckBoxAutomation.isChecked()) {
mAutomationPermLayout.setVisibility(LinearLayout.VISIBLE);
pageArray.add("automationPage");
} else {
mAutomationPermLayout.setVisibility(LinearLayout.GONE);
pageArray.remove("automationPage");
}
这是我转换为字符串的方式
String pageString = pageArray.toString();
Log.e("PAGES", pageString);
【问题讨论】:
标签: java android string checkbox arraylist