ChrisBanes PullToRefresh 'Loading ...' issue

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

I implemented it successfully thanks to its docs. :)

However, I am stuck at this point now. I use volley to get data from the server. It works fine until I add a check to see if there is more data, and then just a user toast.

I liked it below

@Override public void onRefresh( PullToRefreshBase<ListView> refreshView) { if (hasMoreData()){ //Call service when pulled to refresh orderService(); } else{ // Call onRefreshComplete when the list has been refreshed. toastShort("No more data to load"); orderListAdapter.notifyDataSetChanged(); mPullRefreshListView.onRefreshComplete(); } } 

A toast appears, but I also continue to see the message Loading ... below my ListView. I thought onRefreshComplete(); must take care of this, but it is not.

How can I do it? Please, help.

+4
source share
2 answers

After I hit my head for almost three hours, I was able to solve this. It was quite difficult.

As a result, I created a handler and Runnable that calls mPullRefreshListView.onRefreshComplete(); , and after a while checks that if mPullRefreshListView is still being updated, then call the method again, which closes it the next time it is called. :)

The code is as follows.

 @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.

+3
source

you must use onRefreshComplete(); in a separate thread, for example:

  @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
source

Source: https://habr.com/ru/post/1490178/


All Articles