rickkorsten rickkorsten - 1 year ago 103
Java Question

Set the text of a Textview from a returned String array

public String[] getpathsFromJSON (String JSONStringparam) throws JSONException{

JSONObject JSONString = new JSONObject(JSONStringparam);

JSONArray seriearray = JSONString.getJSONArray("results");
String [] result = new String [seriearray.length()];

for (int i = 0; i<seriearray.length();i++){
JSONObject serie = seriearray.getJSONObject(i);
String serienaam = serie.getString("name");
result[i] = serienaam;
return result;

i want to use one of the results in the return to display in a textview.
what is the best way to do this?

Answer Source

You want to use just one result?

TextView view = (TextView) findViewById(R.id.yourTextViewResourceId); 


Since you're programming for Android I'm assuming you're using Android Studio so you can create the text view in the GUI interface for the XML and use findViewById.

If you want to display them all:

LinearLayout linearLayout = (LinearLayout) findViewById(R.id.layoutViewEx);

for (int i = 0; i < result.length(); i++) {
        TextView textView = new TextView(getActivity());           
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download