Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

android AsyncTaskLoader sample

View SampleEndlessLoader.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
public static class SampleEndlessLoader extends AsyncTaskLoader<List<String>> {
 
EventManager evManager;
int itemCount = 0;
boolean isLoading = false;
 
public SampleEndlessLoader(Context context, EventManager evManager) {
super(context);
Log.d(LOG_TAG, "EndlessLvFrag.SampleLoader.SampleLoader:");
this.evManager = evManager;
}
 
@Override
public void forceLoad() {
if (!isLoading) {
super.forceLoad();
isLoading = !isLoading;
}
}
 
@Override
public List<String> loadInBackground() {
Log.d(LOG_TAG, "EndlessLvFrag.onCreateLoader(...).new AsyncTaskLoader() {...}.loadInBackground:");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ArrayList<String> result = new ArrayList<String>();
for (int i = 0; i < 10; i++) {
result.add("item_" + itemCount++);
}
Log.d(LOG_TAG, "EndlessLvFrag.onCreateLoader(...).new AsyncTaskLoader() {...}.loadInBackground: finished");
isLoading = false;
return result;
}
 
@Override
protected void onStartLoading() {
Log.d(LOG_TAG, "EndlessLvFrag.SampleLoader.onStartLoading:" + isLoading);
forceLoad();
}
 
@Override
protected void onForceLoad() {
super.onForceLoad();
evManager.fire(new DataLoadingEvent(true));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.