Reputation: 131
My json array responce for item location as "id_location" : "1" or 2 ect i want to display the equal value " location name" in my site insted of the numbers. So how to check and change it beforre setText , changing it by using ready value from string.xml is a good idea but how to do it Thanks in advance
EDIT This is how i get json
List adlist = new List();
ad.setTitle(obj.getString("id_location"));
With list adapter
-------EDIT 2------ If alians saw this in futer.. Thanks to mr.vaspalls This is the fainal working code :
//m.getLocation() is your json returned string
switch(m.getLocation()){
case "1": textview.setText("New York");
break;
case "2": textview.setText("London");
break;
.....
}
Upvotes: 0
Views: 43
Reputation: 4549
if you already know all the default values for the cities, you can either save them in the String.xml for save it in a class like this
String[] location = {"","London","Berlin","Mascow"}
OR
String[] location = getResources().getStringArray(R.array.location);
I made the first index empty as i don't know if you will be getting a location value for it.
but if you have a value for 0 like "some city", then location array should not be empty at index 0
int index = Integer.parseInt(jsonObject.getString("id_location"));
textView.setText(""+location[i]);
Upvotes: 1
Reputation: 4877
The easiest way is to do that with switch
like this
switch(id_location){
case "1": city = "New York";
break;
case "2": city = "London";
break;
.....
}
Upvotes: 1