Я никогда не использовал вложенный оператор switch. Просто хотел знать, что использование вложенного оператора switch хорошо в моем коде или нет.
Я получил 3 целочисленных переменных. тип и позиция значения 0
или 1
на обоих и элемент с 0
до 6
.
Мой код слишком длинный, чтобы его сократить:
public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long id) {
type = spinner_type.getSelectedItemPosition();
position = spinner_pos.getSelectedItemPosition();
item = spinner.getSelectedItemPosition();
switch (adapterView.getId()) {
case R.id.cck_spinner_type:
switch (pos) {
case 0:
if(position == 0 && item == 0) {
sp_name = "cc_left";
} else if(position == 0 && item == 1){
sp_name = "cc_left1";
} else if(position == 0 && item == 2){
sp_name = "cc_left2";
}else if(position == 0 && item == 3){
sp_name = "cc_left3";
}else if(position == 0 && item == 4){
sp_name = "cc_left4";
}else if(position == 0 && item == 5){
sp_name = "cc_left5";
}else if(position == 0 && item == 6){
sp_name = "cc_left6";
}else if(position == 1 && item == 0) {
sp_name = "cc_right";
} else if(position == 1 && item == 1){
sp_name = "cc_right1";
} else if(position == 1 && item == 2){
sp_name = "cc_right2";
}else if(position == 1 && item == 3){
sp_name = "cc_right3";
}else if(position == 1 && item == 4){
sp_name = "cc_right4";
}else if(position == 1 && item == 5){
sp_name = "cc_right5";
}else if(position == 1 && item == 6){
sp_name = "cc_right6";
}
break;
case 1:
if(position == 0 && item == 0) {
sp_name = "ccL_left";
} else if(position == 0 && item == 1){
sp_name = "ccL_left1";
} else if(position == 0 && item == 2){
sp_name = "ccL_left2";
}else if(position == 0 && item == 3){
sp_name = "ccL_left3";
}else if(position == 0 && item == 4){
sp_name = "ccL_left4";
}else if(position == 0 && item == 5){
sp_name = "ccL_left5";
}else if(position == 0 && item == 6){
sp_name = "ccL_left6";
}else if(position == 1 && item == 0) {
sp_name = "ccL_right";
} else if(position == 1 && item == 1){
sp_name = "ccL_right1";
} else if(position == 1 && item == 2){
sp_name = "ccL_right2";
}else if(position == 1 && item == 3){
sp_name = "ccL_right3";
}else if(position == 1 && item == 4){
sp_name = "ccL_right4";
}else if(position == 1 && item == 5){
sp_name = "ccL_right5";
}else if(position == 1 && item == 6){
sp_name = "ccL_right6";
}
break;
}
break;
case R.id.cck_spinner_pos:
switch (pos) {
case 0:
if(type == 0 && item == 0) {
sp_name = "cc_left";
} else if(type == 0 && item == 1){
sp_name = "cc_left1";
} else if(type == 0 && item == 2){
sp_name = "cc_left2";
}else if(type == 0 && item == 3){
sp_name = "cc_left3";
}else if(type == 0 && item == 4){
sp_name = "cc_left4";
}else if(type == 0 && item == 5){
sp_name = "cc_left5";
}else if(type == 0 && item == 6){
sp_name = "cc_left6";
}else if(type == 1 && item == 0) {
sp_name = "ccL_left";
} else if(type == 1 && item == 1){
sp_name = "ccL_left1";
} else if(type == 1 && item == 2){
sp_name = "ccL_left2";
}else if(type == 1 && item == 3){
sp_name = "ccL_left3";
}else if(type == 1 && item == 4){
sp_name = "ccL_left4";
}else if(type == 1 && item == 5){
sp_name = "ccL_left5";
}else if(type == 1 && item == 6){
sp_name = "ccL_left6";
}
break;
case 1:
if(type == 0 && item == 0) {
sp_name = "cc_right";
} else if(type == 0 && item == 1){
sp_name = "cc_right1";
} else if(type == 0 && item == 2){
sp_name = "cc_right2";
}else if(type == 0 && item == 3){
sp_name = "cc_right3";
}else if(type == 0 && item == 4){
sp_name = "cc_right4";
}else if(type == 0 && item == 5){
sp_name = "cc_right5";
}else if(type == 0 && item == 6){
sp_name = "cc_right6";
}else if(type == 1 && item == 0) {
sp_name = "ccL_right";
} else if(type == 1 && item == 1){
sp_name = "ccL_right1";
} else if(type == 1 && item == 2){
sp_name = "ccL_right2";
}else if(type == 1 && item == 3){
sp_name = "ccL_right3";
}else if(type == 1 && item == 4){
sp_name = "ccL_right4";
}else if(type == 1 && item == 5){
sp_name = "ccL_right5";
}else if(type == 1 && item == 6){
sp_name = "ccL_right6";
}
break;
default:
Toast.makeText(getContext(),"ERR 208",Toast.LENGTH_SHORT).show();
}
break;
case R.id.cck_spinner:
switch (pos) {
case 0:
if (type == 0 && position == 0) {
sp_name = "cc_left";
} else if (type == 0 && position == 1) {
sp_name = "cc_right";
} else {
Toast.makeText(getContext(), "You can't change LABEL of this key", Toast.LENGTH_SHORT).show();
}
break;
case 1:
if (type == 0 && position == 0) {
sp_name = "cc_left1";
} else if (type == 0 && position == 1) {
sp_name = "cc_right1";
} else if (type == 1 && position == 0) {
sp_name = "ccL_left1";
} else if (type == 1 && position == 1) {
sp_name = "ccL_right1";
}
break;
case 2:
if (type == 0 && position == 0) {
sp_name = "cc_left2";
} else if (type == 0 && position == 1) {
sp_name = "cc_right2";
} else if (type == 1 && position == 0) {
sp_name = "ccL_left2";
} else if (type == 1 && position == 1) {
sp_name = "ccL_right2";
}
break;
case 3:
if (type == 0 && position == 0) {
sp_name = "cc_left3";
} else if (type == 0 && position == 1) {
sp_name = "cc_right3";
} else if (type == 1 && position == 0) {
sp_name = "ccL_left3";
} else if (type == 1 && position == 1) {
sp_name = "ccL_right3";
}
break;
case 4:
if (type == 0 && position == 0) {
sp_name = "cc_left4";
} else if (type == 0 && position == 1) {
sp_name = "cc_right4";
} else if (type == 1 && position == 0) {
sp_name = "ccL_left4";
} else if (type == 1 && position == 1) {
sp_name = "ccL_right4";
}
break;
case 5:
if (type == 0 && position == 0) {
sp_name = "cc_left5";
} else if (type == 0 && position == 1) {
sp_name = "cc_right5";
} else if (type == 1 && position == 0) {
sp_name = "ccL_left5";
} else if (type == 1 && position == 1) {
sp_name = "ccL_right5";
}
break;
case 6:
if (type == 0 && position == 0) {
sp_name = "cc_left6";
} else if (type == 0 && position == 1) {
sp_name = "cc_right6";
} else if (type == 1 && position == 0) {
sp_name = "ccL_left6";
} else if (type == 1 && position == 1) {
sp_name = "ccL_right6";
}
break;
default:
if (type == 0 && position == 0) {
sp_name = "cc_left";
} else if (type == 0 && position == 1) {
sp_name = "cc_right";
} else {
Toast.makeText(getContext(), "You can't change LABEL of this key", Toast.LENGTH_SHORT).show();
}
}
break;
}
pfKey4.setHint(sp.getString(sp_name, "not_found"));
}