如何在复选框数组中添加微调器,当选中微调器将激活的复选框时,当从微调器中选择时,它将在textView中显示结果并在更改微调器选择更改时更改 如果我写
selection.add(txt + "Body Towels");
它只显示(1毛巾),如果我选择另一个号码,则永远不会改变
这是我的方法代码
@Override
public void onClick(View v) {
//spinners for string array numbers 1-5
final Spinner spinner = (Spinner) findViewById(R.id.bbodytowelssp);
spinner.setEnabled(false);
final ArrayAdapter<String> adapter = new ArrayAdapter<String>
(HouseKeeping.this, android.R.layout.simple_spinner_item, getResources().getStringArray
(R.array.numbers));
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
txt = adapter.getItem(position).toString();//selected spinner
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
//for checkbox
// I want to add spinners here and added to selection like example (2 Body Towels)
boolean checked = ((CheckBox) v).isChecked();
switch (v.getId()) {
case R.id.bbodytowelscb:
if (checked) {
spinner.setEnabled(true);//first spinner
selection.add("Body Towels");
} else {
selection.remove("Body Towels");
result.setText("");
}
break;
case R.id.bbodylotioncb:
if (checked) {
selection.add("Body Lotion");
} else {
selection.remove("Body Lotion");
result.setText("");
}
break;
case R.id.bbrushcb:
if (checked) {
selection.add("Brush");
} else {
selection.remove("Brush");
result.setText("");
}
break;
case R.id.bconditionercb:
if (checked) {
selection.add("Conditioner");
} else {
selection.remove("Conditioner");
result.setText("");
}
break;
case R.id.bhandtowelscb:
if (checked) {
selection.add("Hand Towels");
} else {
selection.remove("Hand Towels");
result.setText("");
}
break;
case R.id.bshampoocb:
if (checked) {
selection.add("Shampoo");
} else {
selection.remove("Shampoo");
result.setText("");
}
break;
case R.id.bshowergelcb:
if (checked) {
selection.add("Shower Gel");
} else {
selection.remove("Shower Gel");
result.setText("");
}
break;
case R.id.btoothsetscb:
if (checked) {
selection.add("Tooth Sets");
} else {
selection.remove("Tooth Sets");
result.setText("");
}
break;
}
String final_selection = "";
for (String s : selection) {
final_selection = final_selection + s + " "; //show checkbox result
result.setText(final_selection); //the textView
result.setEnabled(true);
}
}