확인란을 선택 해제 한 후에도 배열 목록에서 값을 제거하는 두 가지 방법을 시도했지만 아직 성공하지 못한 것 같습니다.다른 체크 박스를 선택했을 때 ArrayList <String>에서 값을 제거하는 방법
아래 코드에는 각 상자에 대한 사례가 들어있는 switch 문이 포함되어 있습니다. 기본적으로 사용자가 상자 중 하나를 선택하면 ArrayList<String>
에 값을 저장 한 다음 다른 방법으로 값을 저장합니다. messageTotalTip = selection.get(0);
미리 감사드립니다.
/* Create a View for our Check Boxes */
public void selectTip(View view){
/*Boolean object will check if our checkbox is checked or not*/
boolean checked =((CheckBox) view).isChecked();
switch (view.getId()){
/*Case if 15% is clicked*/
case R.id.cb15Percent:
if(checked){
/*store our value into the ArrayList*/
selection.add("15");
/*To make sure we cant click any other box*/
cb18Percent.setChecked(false);
cb20Percent.setChecked(false);
cbCustomTip.setChecked(false);
/*Try and make sure that our value is erased if unchecked */
if(cb18Percent.isChecked() || cb20Percent.isChecked()||cbCustomTip.isChecked()) {
selection.remove("15");
}
} else {
selection.remove("15");
}
break;
/*Case if 18% is clicked*/
case R.id.cb18Percent:
if(checked){
/*store our value into the ArrayList*/
selection.add("18");
/*Make sure we cant click any other box*/
cb15Percent.setChecked(false);
cb20Percent.setChecked(false);
cbCustomTip.setChecked(false);
/*Try and make sure that our value is erased if unchecked */
if(cb15Percent.isChecked() || cb20Percent.isChecked()||cbCustomTip.isChecked()) {
selection.remove("18");
}
} else {
selection.remove("18");
}
break;
/*Case if 20% is clicked*/
case R.id.cb20Percent:
if(checked) {
/*store our value into the ArrayList*/
selection.add("20");
/*Make sure we cant click any other box*/
cb15Percent.setChecked(false);
cb18Percent.setChecked(false);
cbCustomTip.setChecked(false);
/*Try and make sure that our value is erased if unchecked */
if(cb18Percent.isChecked() || cb15Percent.isChecked()||cbCustomTip.isChecked()) {
selection.remove("20");
}
} else {
selection.remove("20");
}
break;
/*Case if the custom box is checked*/ /************ Add dialogue box later once smaller bugs are fixed ************/
case R.id.cbCustom:
if(checked){
selection.add("100");
/*Make sure we cant click any other box*/
cb15Percent.setChecked(false);
cb18Percent.setChecked(false);
cb20Percent.setChecked(false);
/*Try and make sure that our value is erased if unchecked */
if(cb18Percent.isChecked() || cb20Percent.isChecked()||cb15Percent.isChecked()) {
selection.remove("100");
}
}else {
selection.remove("100");
}
}
}
1. 언제든지 한 번만 검사 할 수 있습니까? 2. 적어도 하나는 확인해야합니까? –
예, 예! 이것은 간단한 팁 계산기입니다. 팁을 계산하고 싶기 때문에 팁을 계산할 수 있도록 단 하나의 값만 가질 수 있어야합니다. – Robbie08
대신 라디오 버튼을 사용하지 않는 이유는 무엇입니까? – jonhid