I have ListFragment and AsyncTaskLoader which fetches data from internet. ListFragment is filled by BaseAdapter.
When data is loading, BaseAdapter fills the first row with spinning progress bar. When data is loaded and no errors occured, data is filled into ListView. But if some error occured(I have a flag in AsyncTaskLoader indicating that error), then BaseAdapter fill the first row with error message.
Problem:
When loading has errors, LoaderManager automatically tries to load data again(forceLoad()
called), which is good. But what I need is to notify BaseAdapter that data is loading so BaseAdapter can change error message to spinning progress bar.
Is there any easy good way to notify fragment when LoaderManager is calling forceLoad()
?
My suggestion:
ListFragment will implement the interface below and pass this ListFragment in AsyncTaskLoader's constructor.
public interface LoadingListener {
public void onLoadingStatusChanged(boolean isLoading);
}
Then I can call onLoadingStatusChanged(true)
in loadInBackground()
and onLoadingStatusChanged(false)
in deliverResult(T data)
. I am affraid that holding reference to Fragment in AsyncTaskLoader may leak that fragment.