下面列出了android.support.v4.app.LoaderManager#restartLoader ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void loadListViewItems(int listPosition, boolean markSeen, boolean showProgress) {
if (!isAdded()) {
return;
}
int loaderId = 0;
ConversationsLoaderCallbacks callbacks =
new ConversationsLoaderCallbacks(getContext(), listView,
listPosition, cursorAdapter, markSeen, showProgress);
LoaderManager manager = getLoaderManager();
Loader<?> loader = manager.getLoader(loaderId);
if (loader == null) {
// init and run the items loader
manager.initLoader(loaderId, null, callbacks);
} else {
// restart loader
manager.restartLoader(loaderId, null, callbacks);
}
}
private void loadListViewItems(String itemsFilter, boolean deleteItems, int listPosition) {
if (!isAdded()) {
return;
}
int loaderId = 0;
JournalItemsLoaderCallbacks callbacks =
new JournalItemsLoaderCallbacks(getContext(), cursorAdapter,
itemsFilter, deleteItems, listView, listPosition);
LoaderManager manager = getLoaderManager();
if (manager.getLoader(loaderId) == null) {
// init and run the items loader
manager.initLoader(loaderId, null, callbacks);
} else {
// restart loader
manager.restartLoader(loaderId, null, callbacks);
}
}
private void loadListViewItems(int threadId, int unreadCount, int listPosition) {
if (!isAdded()) {
return;
}
int loaderId = 0;
ConversationLoaderCallbacks callbacks =
new ConversationLoaderCallbacks(getContext(),
threadId, unreadCount, listView, listPosition, cursorAdapter);
LoaderManager manager = getLoaderManager();
if (manager.getLoader(loaderId) == null) {
// init and run the items loader
manager.initLoader(loaderId, null, callbacks);
} else {
// restart loader
manager.restartLoader(loaderId, null, callbacks);
}
}
private void loadListViewItems(String itemsFilter, boolean deleteItems, int listPosition) {
if (!isAdded()) {
return;
}
int loaderId = 0;
ContactsLoaderCallbacks callbacks =
new ContactsLoaderCallbacks(getContext(), contactType, cursorAdapter,
itemsFilter, deleteItems, listView, listPosition);
LoaderManager manager = getLoaderManager();
if (manager.getLoader(loaderId) == null) {
// init and run the items loader
manager.initLoader(loaderId, null, callbacks);
} else {
// restart loader
manager.restartLoader(loaderId, null, callbacks);
}
}
public void loadNext(View view){
//获取LoaderManager
LoaderManager loaderManager = getSupportLoaderManager();
//LoaderManager.restartLoader
loaderManager.restartLoader(1,null,this);
}
/**
* Re-query database.
*
* @param forceUpdate force update
*/
public void requery(final boolean forceUpdate) {
Log.d(TAG, "requery(", forceUpdate, ")");
if (!this.ignoreQuery) {
LoaderManager lm = getLoaderManager();
if (forceUpdate && lm.getLoader(uid) != null) {
lm.restartLoader(uid, null, this);
} else {
lm.initLoader(uid, null, this);
}
} else {
Log.d(TAG, "requery(", forceUpdate, "): ignore");
}
}
/**
* This method retrieves the search text from the EditText, constructs the
* URL (using {@link NetworkUtils}) for the github repository you'd like to find, displays
* that URL in a TextView, and finally request that an AsyncTaskLoader performs the GET request.
*/
private void makeGithubSearchQuery() {
String githubQuery = mSearchBoxEditText.getText().toString();
/*
* If the user didn't enter anything, there's nothing to search for. In the case where no
* search text was entered but the search button was clicked, we will display a message
* stating that there is nothing to search for and we will not attempt to load anything.
*
* If there is text entered in the search box when the search button was clicked, we will
* create the URL that will return our Github search results, display that URL, and then
* pass that URL to the Loader. The reason we pass the URL as a String is simply a matter
* of convenience. There are other ways of achieving this same result, but we felt this
* was the simplest.
*/
if (TextUtils.isEmpty(githubQuery)) {
mUrlDisplayTextView.setText("No query entered, nothing to search for.");
return;
}
URL githubSearchUrl = NetworkUtils.buildUrl(githubQuery);
mUrlDisplayTextView.setText(githubSearchUrl.toString());
Bundle queryBundle = new Bundle();
queryBundle.putString(SEARCH_QUERY_URL_EXTRA, githubSearchUrl.toString());
/*
* Now that we've created our bundle that we will pass to our Loader, we need to decide
* if we should restart the loader (if the loader already existed) or if we need to
* initialize the loader (if the loader did NOT already exist).
*
* We do this by first store the support loader manager in the variable loaderManager.
* All things related to the Loader go through through the LoaderManager. Once we have a
* hold on the support loader manager, (loaderManager) we can attempt to access our
* githubSearchLoader. To do this, we use LoaderManager's method, "getLoader", and pass in
* the ID we assigned in its creation. You can think of this process similar to finding a
* View by ID. We give the LoaderManager an ID and it returns a loader (if one exists). If
* one doesn't exist, we tell the LoaderManager to create one. If one does exist, we tell
* the LoaderManager to restart it.
*/
LoaderManager loaderManager = getSupportLoaderManager();
Loader<String> githubSearchLoader = loaderManager.getLoader(GITHUB_SEARCH_LOADER);
if (githubSearchLoader == null) {
loaderManager.initLoader(GITHUB_SEARCH_LOADER, queryBundle, this);
} else {
loaderManager.restartLoader(GITHUB_SEARCH_LOADER, queryBundle, this);
}
}
/**
* Set Adapter.
*
* @param forceUpdate force update
*/
public void setAdapter(final boolean forceUpdate) {
LogAdapter adapter = (LogAdapter) getListAdapter();
if (!forceUpdate && adapter != null && !adapter.isEmpty()) {
return;
}
String where = DataProvider.Logs.TABLE + "." + DataProvider.Logs.TYPE + " in (-1";
if (tbCall != null && tbCall.isChecked()) {
where += "," + DataProvider.TYPE_CALL;
}
if (tbSMS != null && tbSMS.isChecked()) {
where += "," + DataProvider.TYPE_SMS;
}
if (tbMMS != null && tbMMS.isChecked()) {
where += "," + DataProvider.TYPE_MMS;
}
if (tbData != null && tbData.isChecked()) {
where += "," + DataProvider.TYPE_DATA;
}
where += ") and " + DataProvider.Logs.TABLE + "." + DataProvider.Logs.DIRECTION + " in (-1";
if (tbIn != null && tbIn.isChecked()) {
where += "," + DataProvider.DIRECTION_IN;
}
if (tbOut != null && tbOut.isChecked()) {
where += "," + DataProvider.DIRECTION_OUT;
}
where += ")";
if (planId > 0L && tbPlan != null && tbPlan.isChecked()) {
String plans = DataProvider.Plans.parseMergerWhere(getActivity()
.getContentResolver(), planId);
where = DbUtils.sqlAnd(plans, where);
Log.d(TAG, "where: ", where);
}
Bundle args = new Bundle(1);
args.putString("where", where);
LoaderManager lm = getLoaderManager();
if (lm.getLoader(LOADER_UID) == null) {
lm.initLoader(LOADER_UID, args, this);
} else {
lm.restartLoader(LOADER_UID, args, this);
}
}