Skip to content

@kingori /SampleEndlessLoader.java
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
android AsyncTaskLoader sample
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.