1
다음 클래스 (AsyncTask)를 사용하여 8 개의 다른 URL에서 정보를 검색하고 있습니다. 검색된 데이터를 8 개의 요소 (데이터를 가져 오는 각 URL마다 하나씩)의 배열에 저장하려고합니다.여러 URL에서 데이터를 가져와 간단한 배열에 저장하는 방법은 무엇입니까?
private class getDataClass extends AsyncTask<String, Void, String>{
protected String doInBackground(String...urls){
String response = "";
for(String url : urls){
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try{
HttpResponse execute = client.execute(httpGet);
InputStream content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
String s = "";
while((s = buffer.readLine()) != null){
response += s;
}
}catch(Exception e){
e.printStackTrace();
}
}
return response;
}
protected void onPostExecute(String result){
Resources.descriptionArray[descriptionArray_Counter] = Html.fromHtml(result).toString();
descriptionArray_Counter++;
}
그리고 이런 식으로 전화 :
getDataClass getData = new getDataClass();
getData.execute(description_links);
을 내가 분명히 받고 있어요 문제는 모든 정보가 배열에 저장되는 [0], 내 AsyncTask를 클래스는 하나의 "응답"을 반환로 끈.
내가 알고 싶은 것은, 이것의 많은 예를 발견하지 못했기 때문에 이것을하는 더 우아한 방법이 무엇인지, 그리고 어떻게 경험이 많은 다른 코더들이이 문제에 관해서 이야기 할 수 있는가하는 것이다.
시간을내어 답변 해 주셔서 감사합니다.
감사를 확인해야합니다. 이것을 구현하는 방법에 대한 도움이 필요하십니까? 아니면 아마도 링크일까요? – Eugen
링크를 확인하십시오. –
고마워요! :디 – Eugen