@Override public void onScroll(AbsListView view, int firstVisible, int visibleCount, int totalCount) { if (mObjects == null) return; boolean loadMore = /* maybe add a padding */ firstVisible + visibleCount >= mObjects.getTotalQueried(); if (loadMore) { mLoader.cancelLoad(); if (getActivity() instanceof Filterable) { Filterable context = (Filterable) getActivity(); if (context != null) { List<String> filterTypes = new ArrayList<String>(); for (int x = 0; x < context.getFilterTypes().length; x++) { if (context.getFilterCheckboxes()[x]) { Log.w(TAG, "adding " + context.getFilterTypes()[x]); filterTypes.add(context.getFilterTypes()[x]); } } mLoader = mObjects.queryLaterObjects( getActivity(), mFeedUri, totalCount, filterTypes.toArray(new String[filterTypes.size()])); } } else { mLoader = mObjects.queryLaterObjects(getActivity(), mFeedUri, totalCount, null); } } }
@Override public void onDestroy() { super.onDestroy(); if (mLoader != null) { mLoader.cancelLoad(); } // the mObjects field is accessed by the background loader synchronized (this) { if (mObjects != null) { ((ObjectListCursorAdapter) mObjects).closeCursor(); } } }