我有一个可以联系的 Web 服务,但我必须向 Web 服务添加一个 Skip 和 Take 整数,以限制我返回的结果数量,因为会有数百个地址。所以下面发布的是我联系webservice的android方法,但是我如何为我的android应用程序更改下面的活动代码,这样我就可以限制说十个结果,第一次跳过0,然后连续跳过十个。
我的安卓活动:
public List<FuelStops> getFuelStops() throws URISyntaxException, ClientProtocolException, IOException, ParserConfigurationException, SAXException{
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
BufferedReader in = null;
String page;
fuelStopList = new ArrayList<FuelStops>();
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI("http://google.com/Service1.asmx/GetFuelStops"));
HttpResponse response = client.execute(request);
in = new BufferedReader
(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
page = sb.toString();
FuelStops fuelStop=new FuelStops();
StringBuilder addressStrBlder = new StringBuilder();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(new StringReader(page)));
// normalize the document
doc.getDocumentElement().normalize();
// get the root node
NodeList nodeList = doc.getElementsByTagName("FuelStop");
Node node=nodeList.item(0);
// the node has three child nodes
for (int n = 0; n < nodeList.getLength(); n++) {
for (int i = 0; i < node.getChildNodes().getLength(); i++) {
Node temp=node.getChildNodes().item(i);
if(temp.getNodeName().equalsIgnoreCase("Physical_Address_Street")){
addressStrBlder.append(temp.getTextContent());
}
else if(temp.getNodeName().equalsIgnoreCase("Physical_Address_Local")){
addressStrBlder.append(", " + temp.getTextContent());
}
else if(temp.getNodeName().equalsIgnoreCase("Physical_Address_State")){
addressStrBlder.append(", " + temp.getTextContent());
}
else if(temp.getNodeName().equalsIgnoreCase("Physical_Address_Zip")){
addressStrBlder.append(", " + temp.getTextContent());
fuelStop.setAddress(addressStrBlder.toString());
}
else if(temp.getNodeName().equalsIgnoreCase("Phone_Number")){
fuelStop.setPhoneNum(temp.getTextContent());
fuelStopList.add(fuelStop);
}
}
//Log.e("Fuel Stop", fuelStop.toString());
}
//System.out.println(page);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return fuelStopList;
}
我的网络服务