rickkorsten rickkorsten - 1 month ago 6
Android Question

how do i use a return in a textview

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

You want to use just one result?

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

view.setText(result[some_int_in_your_array]);

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());           
        textView.setText(result[i]);
        linearLayout.addView(textView);
    }
Comments