switch (name){
case "Rusia":
String a="Tuan Rumah"
break;
case "Brazil":
String a="Zona Concacaf"
break;
}
zona.setText(a);
如何在android studio
中将变量“a”显示到zona文本字段中答案 0 :(得分:3)
您需要在switch语句之外定义a
,然后将其设置在里面。例如:
String a = "";
switch (name){
case "Rusia":
a = "Tuan Rumah";
break;
case "Brazil":
a = "Zona Concacaf";
break;
default:
a = "Unknown";
}
zona.setText(a);
答案 1 :(得分:1)
将其定义为开关块:
String a = "default";
switch (name){
case "Rusia":
a="Tuan Rumah"
break;
case "Brazil":
a="Zona Concacaf"
break;
}
zona.setText(a);
答案 2 :(得分:0)
String a = "";
switch (name){
case "Rusia":
a = "Tuan Rumah";
break;
case "Brazil":
a = "Zona Concacaf";
break;
}
if(!TextUtils.isEmpty(a))
zona.setText(a);
答案 3 :(得分:0)
定义变量' a'在switch语句之外和之前:
String a ="":
Switch()