I have managed to created a JSON endpoint on my website. This JSON is fed into my android project,parsed and stored in a list view. The issue i'm having is that, rather than printing each JSON object in each element of the list, a JSON object is being added - making each element of the list longer.
An example of the list:
Data1
Data1 Data2
Data1 Data2 Data3
Data1 Data2 Data3 Data4
I am looking for:
Data1
Data2
Data3
My code is as follows, could anybody please be so kind as to point out where I may be going wrong?
public void setTextToTextView(JSONArray jsonArray){
String s = "";
CharSequence news_title = getResources().getText(R.string.news_title);
ArrayList<String> arrayList = new ArrayList<String>();
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,R.layout.simplerow,R.id.rowTextView, arrayList);
for (int i=0; i<jsonArray.length(); i++){
JSONObject jsonResponse;
try {
jsonResponse = jsonArray.getJSONObject(i);
s = s +
Html.fromHtml(news_title.toString())
+jsonResponse.getString("subject")+"\n"+
"Posted By :"+jsonResponse.getString("postedby")+"\n"+"\n";
arrayList.add(s);
} catch (JSONException e) {
e.printStackTrace();
}
}
Log.e("JSON Response:", arrayList.toString());
arrayAdapter.add(s);
this.newsResponseListView.setAdapter(arrayAdapter);
}