ChrisBanes PullToRefresh 'Loading…' issue

前端 未结 2 579
挽巷
挽巷 2021-01-13 12:49

I am using PullToRefresh ListView from chrisbanes which I found here.

I implemented it successfully, thanks to its documentations. :)

However, I am stuck at

相关标签:
2条回答
  • 2021-01-13 13:33

    After banging my head for almost 3hours I was able to solve this. It was quite simple tough.

    What I did was created a Handler and a Runnable which calls mPullRefreshListView.onRefreshComplete(); and checked after some time that if mPullRefreshListView was still refreshing then call the method again which closes it on the next call. :)

    Code goes like this..

    @Override
    public void onRefresh(PullToRefreshBase<ListView> refreshView) {
     if (hasMoreData()) {
        // Call service when pulled to refresh
        toastShort("Last");
        orderService();
     } else {
        // Call onRefreshComplete when the list has been
        // refreshed.
        toastShort("No more data to load");
        upDatePull();  //this method does the trick
     }
    }
    
    
    private void upDatePull() {
     // lvOrders.setAdapter(null);
     handler = new Handler();
     handler.postDelayed(runnable, 1000);
    }
    
    Runnable runnable = new Runnable() {
    @Override
    public void run() {
        mPullRefreshListView.onRefreshComplete();
        if (mPullRefreshListView.isRefreshing()) {
            Logger.d("xxx", "trying to hide refresh");
            handler.postDelayed(this, 1000);
        }
    }
    };
    

    Credits to this link.

    0 讨论(0)
  • 2021-01-13 13:48

    you should use onRefreshComplete(); in a separate thread like:

        @Override
    public void onRefresh(PullToRefreshBase<ListView> refreshView) {
         if (hasMoreData()){
    
            //Call service when pulled to refresh
            orderService();
    
         } else{
        toastShort("No more data to load");
        orderListAdapter.notifyDataSetChanged();
    
    }
    new GetDataTask(refreshView).execute();
    

    }

    public class GetDataTask extends AsyncTask<Void, Void, Void> {
    
        PullToRefreshBase<?> mRefreshedView;
    
        public GetDataTask(PullToRefreshBase<?> refreshedView) {
            mRefreshedView = refreshedView;
        }
    
        @Override
        protected Void doInBackground(Void... params) {
            // Do whatever You want here
            return null;
        }
    
        @Override
        protected void onPostExecute(Void result) {
            mRefreshedView.onRefreshComplete();
            super.onPostExecute(result);
        }
    }
    
    0 讨论(0)
提交回复
热议问题