I would like to ask you about the request for list data. If you perform pull-down refresh and pull-up loading requests in the same interface, what is a more appropriate way to process the data when obtaining the request result?
My current approach is to pass the data into the same function, and then judge the request in the function. If it is refreshing, clear the data container, and then add the data. If it is not refreshing, add it directly, but it feels like the code is too complex to handle. It doesn’t look good, and you have to do repeated operations every time you process it, and there is no extraction.
Is there any better solution to this situation?
淡淡烟草味2017-05-16 13:33:18
/**
* 请求数据
* @param page 页码
* @param status 状态 是刷新 还是加载更多
*/
private void loadData(int page,int status){
HttpUtil.with(..)
.url(..)
.param(..)
.excute(new Callback(){
void onSuccess(List<bean> result){
if(status == REFRESH_STATUS){//刷新状态
datas.clear();
}
datas.addALL(result);
adapter.notifyDataSetChanged();
}
});
}
漂亮男人2017-05-16 13:33:18
The interface generally requires the page parameter. Page=0 is usually a pull-down refresh