Android 拉动刷新一直加载

Android Pull to refresh keeps loading

我已经在应用程序中实现了 Android-PullToRefresh。一切正常,但在列表视图中加载数据后,拉动刷新继续加载。

    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();
                    }
                }
            }));

下面是我使用的post执行方法

@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);
            }

谁能告诉我哪里漏掉了。我花了一整天的时间才找到这个问题。请帮帮我。

提前致谢。

你需要打电话

list.onRefreshComplete();

只要您的任务完成,您就需要调用 onRefreshComplete()

protected void onPostExecute(String result)
    {
        dialog.dismiss();
        list.onRefreshComplete();
    }

当您的数据加载/获取完成后,请不要忘记调用 swipRefreshLayout.setRefreshing(false);