I have two files, the main AnswersForPilots.java:
package com.example.answersforpilots;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
public class AnswersForPilots extends Activity {
getContent theContent;
String json;
ArrayList<ArrayList<String>> questionArray;
ArrayList<ArrayList<String>> answerArray;
LinearLayout parentLayout;
ArrayList<LinearLayout> questionLayout;
ArrayList<TextView> titleView;
ArrayList<TextView> contentView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
theContent = null;
json = null;
questionArray = new ArrayList<ArrayList<String>>();
answerArray = new ArrayList<ArrayList<String>>();
parentLayout = null;
questionLayout = new ArrayList<LinearLayout>();
titleView = new ArrayList<TextView>();
contentView = new ArrayList<TextView>();
populate(this);
}
public void populate(Context context) {
theContent = new getContent();
questionArray = theContent.parseQuestions();
parentLayout = new LinearLayout(context);
for(int i=0; i<questionArray.size(); i++) {
questionLayout.add(new LinearLayout(context));
titleView.add(new TextView(context));
titleView.get(i).setText(questionArray.get(i).get(8).toString());
questionLayout.get(i).addView(titleView.get(i));
contentView.add(new TextView(context));
contentView.get(i).setText(questionArray.get(i).get(9).toString());
questionLayout.get(i).addView(contentView.get(i));
parentLayout.addView(questionLayout.get(i));
}
setContentView(parentLayout);
}
}
And getContent.java:
package com.example.answersforpilots;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
public class getContent {
public String content;
HttpClient hc;
HttpPost post;
HttpResponse rp;
InputStream in;
BufferedReader reader;
StringBuilder str;
String line;
String jContent;
JSONArray jArray;
ArrayList<ArrayList<String>> questionArray;
ArrayList<ArrayList<String>> answerArray;
public getContent() {
content = null;
hc = new DefaultHttpClient();
post = null;
rp = null;
in = null;
reader = null;
str = new StringBuilder();
line = null;
jContent = "";
jArray = null;
questionArray = new ArrayList<ArrayList<String>>();
answerArray = new ArrayList<ArrayList<String>>();
}
public ArrayList<ArrayList<String>> parseQuestions() {
try {
post = new HttpPost("http://answersforpilots.com/
androidPortQuestions.php");
rp = hc.execute(post);
in = rp.getEntity().getContent();
reader = new BufferedReader(new InputStreamReader(in));
while((line = reader.readLine()) != null){
str.append(line + "\n");
}
in.close();
content = str.toString();
jArray = new JSONArray(content);
for(int i=0; i<5 && i<jArray.length(); i++) {
questionArray.add(new ArrayList<String>());
for(int ii=0; ii<11; ii++) {
questionArray.get(i).add(jArray.getJSONObject(i).getString(String.valueOf(ii)));
}
}
} catch(Exception e) { e.printStackTrace(); }
return questionArray;
}
}
Everything is working great, except in
AnswersForPilots.populate()..after the for loop does its job adding a
LinearLayout and 2 TextViews for the title/content all contained
within their respective ArrayLists (for unique IDs), all the TextViews
are added into their parent LinearLayout which is added into the
ParentLayout (LinearLayout). When this all goes on, only the first
ArrayList (questionLayout.get(0), titleView.get(0), and
contentView.get(0)) displays in the ParentLayout on my phone.
Shouldn't all 5 (or more) Layouts/Views appear? Or did I mess
something up?
Hopefully that made sense, if it didn't please ask for clarification!
Thanks,
Sam
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en