Reputation: 27
switch (name){
case "Rusia":
String a="Tuan Rumah"
break;
case "Brazil":
String a="Zona Concacaf"
break;
}
zona.setText(a);
How to show variable "a" into zona textfield in android studio
Upvotes: 1
Views: 52
Reputation: 650
Define variable 'a' outside of switch statement and before it:
String a ="":
Switch()
Upvotes: 0
Reputation: 10270
You need to define a
outside of the switch statement, and then set it inside. For example:
String a = "";
switch (name){
case "Rusia":
a = "Tuan Rumah";
break;
case "Brazil":
a = "Zona Concacaf";
break;
default:
a = "Unknown";
}
zona.setText(a);
Upvotes: 3
Reputation: 58934
String a = "";
switch (name){
case "Rusia":
a = "Tuan Rumah";
break;
case "Brazil":
a = "Zona Concacaf";
break;
}
if(!TextUtils.isEmpty(a))
zona.setText(a);
Upvotes: 0
Reputation: 28269
Define it out the switch block:
String a = "default";
switch (name){
case "Rusia":
a="Tuan Rumah"
break;
case "Brazil":
a="Zona Concacaf"
break;
}
zona.setText(a);
Upvotes: 1