我遇到了m_schedules.get(0).getWeeklyScheduleSet().remove(day);
行的问题
我无法移除Integer
som Set<>
remove函数返回true。如果我问它是否包含对象,则该set返回true。但它根本不会删除它。所以我不知道如何解决这个问题。
private void setupToggleDays() {
ViewGroup daysToggleHolder = (ViewGroup) findViewById(R.id.activity_geofence_schedule_days_holder);
m_daysToggleButtons = new ToggleButton[7];
Calendar cal = Calendar.getInstance();
int currWeekDayIndex = cal.getFirstDayOfWeek();
for (int i = 0; i < 7; i++) {
final int day = currWeekDayIndex;
ToggleButton dayToggleButton = (ToggleButton) daysToggleHolder.getChildAt(i);
m_daysToggleButtons[i] = dayToggleButton;
dayToggleButton.setChecked(m_schedules.get(0).getWeeklyScheduleSet().contains(day));
dayToggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
m_schedules.get(0).getWeeklyScheduleSet().add(day);
}
else {
m_schedules.get(0).getWeeklyScheduleSet().remove(day);
}
}
});
currWeekDayIndex = (currWeekDayIndex % 7) + 1;
}
}
答案 0 :(得分:2)
day
是一个局部变量,您在某个事件中从Set中删除值,因此day
值不是您在方法中设置的值。所以尽量把日子作为场地