這是您可以以字符串數據的形式從服務中獲取數據的方式。
public String getDataFromService()
{
try {
HttpClient httpClient=new DefaultHttpClient();
HttpGet httpGet=new HttpGet(yourserviceURLgoeshere);
HttpResponse httpResponse=httpClient.execute(httpGet);
HttpEntity entity = httpResponse.getEntity();
is=entity.getContent();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return parseExecutedRequest();
}
private String parseExecutedRequest()
{
try {
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder stringBuilder=new StringBuilder();
String line=null;
while((line=bufferedReader.readLine())!=null)
{
stringBuilder.append(line+ "\n");
}
is.close();
result=stringBuilder.toString();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
然後當你以字符串的形式獲取數據。 它可能是xml或json字符串 將該字符串分解成數組或換句話說將數據存儲到數組列表中,如sujit所說。 然後將自動填充框的陣列適配器設置爲您從服務獲得的字符串中創建的ArrayList適配器。 我希望你能得到答案。 –