本文整理汇总了Java中android.app.LoaderManager.initLoader方法的典型用法代码示例。如果您正苦于以下问题:Java LoaderManager.initLoader方法的具体用法?Java LoaderManager.initLoader怎么用?Java LoaderManager.initLoader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.LoaderManager
的用法示例。
在下文中一共展示了LoaderManager.initLoader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.app.LoaderManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
String themes = sharedPrefs.getString(
getString(R.string.settings_themes_key),
getString(R.string.settings_themes_default));
switch (themes) {
case "dark":
setTheme(R.style.AppTheme);
break;
case "light":
setTheme(R.style.AppTheme_Light);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
LoaderManager loaderManager = getLoaderManager();
loaderManager.initLoader(0, null, this);
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
示例2: onActivityCreated
import android.app.LoaderManager; //导入方法依赖的package包/类
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
messageHelper = MessageHelper.getInstance(getActivity());
initializeMessageList();
// This needs to be done before initializing the cursor loader below
initializeSortSettings();
loaderJustInitialized = true;
LoaderManager loaderManager = getLoaderManager();
int len = accountUuids.length;
cursors = new Cursor[len];
cursorValid = new boolean[len];
for (int i = 0; i < len; i++) {
loaderManager.initLoader(i, null, this);
cursorValid[i] = false;
}
}
示例3: onActivityCreated
import android.app.LoaderManager; //导入方法依赖的package包/类
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mLoaderIdlingResource =
new LoaderIdlingResource(getClass().getName() + "/" + getId(), getLoaderManager());
// Load data queries if any.
if (mInitialQueriesToLoad != null && mInitialQueriesToLoad.length > 0) {
LoaderManager manager = getLoaderManager();
for (int i = 0; i < mInitialQueriesToLoad.length; i++) {
manager.initLoader(mInitialQueriesToLoad[i].getId(), null, this);
}
} else {
// No data query to load, update the view.
mUpdatableView.displayData(mModel, null);
}
}
示例4: testStartLoaderThatIsAlreadyInitialized
import android.app.LoaderManager; //导入方法依赖的package包/类
@Test
public void testStartLoaderThatIsAlreadyInitialized() {
final Activity activity = Robolectric.buildActivity(TestActivity.class).create().start().resume().get();
final FragmentManager fragmentManager = activity.getFragmentManager();
final BaseFragment fragment = new TestFragment();
fragmentManager.beginTransaction().add(fragment, null).commit();
fragmentManager.executePendingTransactions();
final LoaderManager loaderManager = fragment.getLoaderManager();
final LoaderManager.LoaderCallbacks mockLoaderCallbacks = mock(LoaderManager.LoaderCallbacks.class);
final Loader firstLoader = new CursorLoader(mApplication, Uri.EMPTY, null, null, null, null);
final Loader secondLoader = new CursorLoader(mApplication, Uri.EMPTY, null, null, null, null);
when(mockLoaderCallbacks.onCreateLoader(1, null)).thenReturn(firstLoader);
loaderManager.initLoader(1, null, mockLoaderCallbacks);
when(mockLoaderCallbacks.onCreateLoader(1, null)).thenReturn(secondLoader);
assertThat(fragment.startLoader(1, null, mockLoaderCallbacks), is(secondLoader));
assertThat(loaderManager.getLoader(1), is(secondLoader));
loaderManager.destroyLoader(1);
}
示例5: onActivityCreated
import android.app.LoaderManager; //导入方法依赖的package包/类
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mMessageHelper = MessageHelper.getInstance(getActivity());
initializeMessageList();
// This needs to be done before initializing the cursor loader below
initializeSortSettings();
mLoaderJustInitialized = true;
LoaderManager loaderManager = getLoaderManager();
int len = mAccountUuids.length;
mCursors = new Cursor[len];
mCursorValid = new boolean[len];
for (int i = 0; i < len; i++) {
loaderManager.initLoader(i, null, this);
mCursorValid[i] = false;
}
}
示例6: onCreate
import android.app.LoaderManager; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAdapter = new SimpleCursorAdapter(getActivity(),
R.layout.structureslist_item, null,
new String[]{StructuresValues.Structures.NAME, StructuresValues.Structures.AWAY},
new int[]{R.id.structure_name, R.id.structure_away}, 0);
setListAdapter(mAdapter);
LoaderManager.LoaderCallbacks<Cursor> mCallbacks = this;
LoaderManager lm = getLoaderManager();
lm.initLoader(LOADER_ID, null, mCallbacks);
}
示例7: onCreate
import android.app.LoaderManager; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAdapter = new SimpleCursorAdapter(getActivity(),
R.layout.historylist_item, null,
new String[]{HistoryValues.History.ENTRY, HistoryValues.History.CREATED_DATE_STR},
new int[]{R.id.history_entry, R.id.history_date}, 0);
setListAdapter(mAdapter);
LoaderManager.LoaderCallbacks<Cursor> mCallbacks = this;
LoaderManager lm = getLoaderManager();
lm.initLoader(LOADER_ID, null, mCallbacks);
}
示例8: onCreate
import android.app.LoaderManager; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAdapter = new SimpleCursorAdapter(getActivity(),
android.R.layout.simple_list_item_1,
null,
new String[] { Direction.FIELD_TITLE },
new int[] { android.R.id.text1 },
0);
setListAdapter(mAdapter);
Bundle bundle = getArguments();
LoaderManager loaderManager = getLoaderManager();
if (bundle != null && loaderManager != null) {
mRouteTag = bundle.getString(SelectRouteFragment.ROUTE_TAG);
loaderManager.initLoader(0, null, this);
}
}
示例9: onCreate
import android.app.LoaderManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_earthquake);
init();
//TODO: verify if there's internet connection
if(thereIsInternet()){
progressBar.setVisibility(View.VISIBLE);
}
else if(!(thereIsInternet())){
progressBar.setVisibility(View.GONE);
noInternetConection.setText("There is no internet connection");
}
// Find a reference to the {@link ListView} in the layout
LoaderManager loaderManager = getLoaderManager();
loaderManager.initLoader(EARTHQUAKE_LOADER, null, this);
//TODO: set up the correct url
earthquakeListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Earthquake earthquake = earthquakeAdapterm.getItem(i);
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(earthquake.getUrl()));
startActivity(intent);
}
});
}
示例10: onPostExecute
import android.app.LoaderManager; //导入方法依赖的package包/类
/**
* Updates the View after the deletion.
* That is, re-enables the menu item that triggered this task, shows a {@link Toast} and refreshes the
* action bar as well as the list itself.
*/
@Override
protected void onPostExecute(Void unused) {
super.onPostExecute(unused);
String toastText = entriesToDelete + " "
+ getResources().getQuantityString(R.plurals.entry, entriesToDelete) + " "
+ getResources().getString(R.string.toast_delete_success);
Toast toast = Toast.makeText(getApplicationContext(), toastText, Toast.LENGTH_SHORT);
//Check achievements for relocked achievements after deletion
AchievementSet.getInstance(getApplicationContext()).checkAchievements();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
/*
* For some reason, at older Android versions, ListView#getCheckedItemCount()
* sums up previous selections even if those
* have already been deleted - even though calling listView.clearChoices() after deleting.
*
* The only way to clear all selections seems to restart the activity...
*/
startActivity(getIntent());
toast.show();
} else {
isEntryChecked = false;
LoaderManager loaderManager = getLoaderManager();
loaderManager.destroyLoader(HISTORY_LOADER);
loaderManager.initLoader(HISTORY_LOADER, null, loaderCallbacks); // Reloads the list.
toast.show();
toDisable.setEnabled(true);
invalidateOptionsMenu();
adapter.notifyDataSetChanged();
}
}
示例11: start
import android.app.LoaderManager; //导入方法依赖的package包/类
/**
* Start the asynchronous request
* Result will be received through the given listener
*/
@Override
public void start(LoaderManager loaderManager, Listener listener) {
if(DBG) Log.d(TAG, "start");
super.start(loaderManager, listener);
loaderManager.initLoader( getLoaderManagerId(), null, this);
}
示例12: init
import android.app.LoaderManager; //导入方法依赖的package包/类
public void init(@NonNull Observer<T> observer) {
final LoaderManager lm = mLmRef.get();
if (lm != null) {
synchronized (LoaderManager.class) {
lm.initLoader(mLoaderId, Bundle.EMPTY, new RxLcImpl<>(mContext, mObservable, observer));
}
}
}
示例13: onCreate
import android.app.LoaderManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] from = {CustomQuoteContract.Quotes.TEXT, CustomQuoteContract.Quotes.SOURCE};
int[] to = {R.id.listitem_custom_quote_text, R.id.listitem_custom_quote_source};
mAdapter = new SimpleCursorAdapter(this, R.layout.listitem_custom_quote, null, from, to, 0);
setListAdapter(mAdapter);
LoaderManager loaderManager = getLoaderManager();
loaderManager.initLoader(0, null, this);
ListView listView = getListView();
registerForContextMenu(listView);
}
示例14: updateEarthquakeData
import android.app.LoaderManager; //导入方法依赖的package包/类
private void updateEarthquakeData() {
ConnectivityManager manager =
(ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
if (QueryUtils.getParamMap() == null) {
displayError(getString(R.string.error_no_params));
} else if (url == null) {
displayError(getString(R.string.error_bad_url));
} else if (!manager.getActiveNetworkInfo().isConnected()) {
displayError(getString(R.string.error_no_connection));
} else {
LoaderManager loaderManager = getLoaderManager();
loaderManager.initLoader(NEWS_LOADER_ID, null, this);
}
}
示例15: testDestroyLoader
import android.app.LoaderManager; //导入方法依赖的package包/类
@Test
public void testDestroyLoader() {
final Activity activity = Robolectric.buildActivity(TestActivity.class).create().start().resume().get();
final FragmentManager fragmentManager = activity.getFragmentManager();
final BaseFragment fragment = new TestFragment();
fragmentManager.beginTransaction().add(fragment, null).commit();
fragmentManager.executePendingTransactions();
final LoaderManager loaderManager = fragment.getLoaderManager();
final LoaderManager.LoaderCallbacks mockLoaderCallbacks = mock(LoaderManager.LoaderCallbacks.class);
when(mockLoaderCallbacks.onCreateLoader(1, null)).thenReturn(new CursorLoader(mApplication, Uri.EMPTY, null, null, null, null));
loaderManager.initLoader(1, null, mockLoaderCallbacks);
fragment.destroyLoader(1);
assertThat(loaderManager.getLoader(1), is(nullValue()));
}