Pull to refresh给出了不同的数据(不是从初始数据开始),因为以下代码中的pageNumber增加了。当在infiniteContainer中调用pull to refresh时,如何将pageNumber int的值设置为零?
InfiniteContainer ic = new InfiniteContainer() {
@Override
public Component[] fetchComponents(int index, int amount) {
ArrayList<Map<String, Object>> data = fetchHerbData(res);
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
}
};
int pageNumber = 0;
ArrayList<Map<String, Object>> fetchHerbData(Resources res) {
try {
ConnectionRequest r = new ConnectionRequest();
r.setPost(false);
r.setUrl("http://api.nestoria.co.uk/api");
r.addArgument("pretty", "0");
r.addArgument("action", "search_listings");
r.addArgument("encoding", "json");
r.addArgument("listing_type", "buy");
r.addArgument("page", "" + pageNumber);
pageNumber++;
r.addArgument("country", "uk");
r.addArgument("place_name", text);
NetworkManager.getInstance().addToQueueAndWait(r);
Map<String,Object> result = new JSONParser().parseJSON(new InputStreamReader(new ByteArrayInputStream(r.getResponseData()), "UTF-8"));
Map<String, Object> response = (Map<String, Object>)result.get("response");
return (java.util.List<Map<String, Object>>)response.get("listings");
} catch(Exception err) {
Log.e(err);
return null;
}
}
答案 0 :(得分:0)
试试这个:
public Component[] fetchComponents(int index, int amount) {
if(index == 0) pageNumber = 0;
//... rest of code
}