I have 3 textviews which I\'m attempting to populate with data from a JSON Http response however they are currently being populated with the incorrect data from the response. >
You have
CommentsLibrary lib = new CommentsLibrary(jsonString, jsonString, jsonString);
All params passed to the constructor of CommentsLibrary is jsonString
. All the three have the same jsonstring.
public CommentsLibrary(String name, String content, String published) {
this.name = name;
this.content = content;
this.published = published;
}
So its the same content that is displayed when you get method for the corresponding fields
Edit:
Declare list as a instance variable
ArrayList list = new ArrayList();
Then
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String name = jsonObject.optString("name","defaultValue");
String content = jsonObject.optString("content","defaultValue");
String published = jsonObject.optString("published","defaultValue");
list.add(new CommentsLibrary(name, content, published));
}
Then in onPostExecute
Use a ListView witha custom adapter and populate the listview with the ArrayList list
.
With text view you only see 1 set of values.