如何将解析后的数据添加到表格布局中?我想通过代码而不是通过 xml 来做到这一点。我应该在哪里创建表格布局并将解析的数据设置为它?因为我无法在 Doinbackground 方法中创建 UI。请帮我。
protected String doInBackground(String... urls) {
Context context;
String response = "";
for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response1;
try {
response1 = client.execute(httpGet);
Log.e("url", response.toString());
HttpEntity entity = response1.getEntity();
// Log.e("response", entity.toString());
is = entity.getContent();
// Log.e("entity",is.toString());
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
result = sb.toString();
Log.e("RES", result.toString());
JSONArray jarray;
try {
jarray = new JSONArray(result);
Email = new String[jarray.length()];
Name = new String[jarray.length()];
Phone = new String[jarray.length()];
Date = new String[jarray.length()];
for (int i = 0; i < jarray.length(); i++) {
JSONObject jobj = jarray.getJSONObject(i);
Email[i] = jobj.getString("Email");
Name[i] = jobj.getString("Name");
Phone[i] = jobj.getString("Phone");
Date[i] = jobj.getString("Date");
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return result;
}