我在应用程序中实现了Android-PullToRefresh。一切正常,但在Listview中加载数据后,刷新的拉动继续加载。
list = (PullToRefreshListView) findViewById(R.id.stored_location);
alertLocationList = list.getRefreshableView();
list.setMode(Mode.PULL_FROM_END);
list.setOnRefreshListener((new PullToRefreshBase.OnRefreshListener< ListView>() {
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
list.onRefreshComplete();
if (Integer.valueOf(totalCount)==Integer.valueOf(endcount)) {
// list.onRefreshComplete();
Log.e(TAG,"----Loaded in listener---");
}
else {
Log.e(TAG,"----calling next data---");
stored_List_Call();
}
}
}));
以下是我使用的后执行方法
@Override
protected void onPostExecute(String result)
{
dialog.dismiss();
switch (asynctaskEnum)
{
case storedLocationList:
try
{
if(result==null)
{
Log.e("result", "result is null");
return;
}
JSONObject header_Object=new JSONObject(result);
if(header_Object.getJSONObject("header").getString("status").equals("1")) {
response_Data(result); //this method parse the Json response and added it to the array list
if(userLocationsAdapter==null) {
Log.e(TAG,"list size--->"+storedUserLocationList.size());
userLocationsAdapter = new StoredLocationAdapter(storedUserLocationList, Activity.this);
alertLocationList.setAdapter(userLocationsAdapter);
}else
{
Log.e(TAG, "list size in else--->" + storedUserLocationList.size());
list.onRefreshComplete();
userLocationsAdapter.notifyDataSetChanged();
}
}
else {
Toast.makeText(Activity.this, "Please try again...", Toast.LENGTH_SHORT).show();
return;
}
}
catch (Exception e) {
e.printStackTrace();
}
break;
default:
break;
}
super.onPostExecute(result);
}
任何人都告诉我在哪里错过了这件事。我花了一整天才找到这个问题。请帮帮我。
提前致谢。
答案 0 :(得分:3)
你需要打电话
list.onRefreshComplete();
只要您的任务完成,您就需要致电onRefreshComplete()
protected void onPostExecute(String result)
{
dialog.dismiss();
list.onRefreshComplete();
}
答案 1 :(得分:-1)
完成数据加载/获取操作后,别忘了致电swipRefreshLayout.setRefreshing(false);