android.support.v4.content.Loader类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(194)

本文整理了Java中android.support.v4.content.Loader类的一些代码示例,展示了Loader类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Loader类的具体详情如下:
包路径:android.support.v4.content.Loader
类名称:Loader

Loader介绍

[英]Static library support version of the framework's android.content.Loader. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.
[中]静态库支持框架的android版本。所容纳之物加载器。用于编写在Android 3.0之前的平台上运行的应用程序。在Android 3.0或更高版本上运行时,仍然使用此实现;它不会尝试切换到框架的实现。有关类概述,请参见框架SDK文档。

代码示例

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
 String[] columns;
 switch (loader.getId()) {
  case LOADER_NAMES:
   columns=COLUMNS_NAMES;
   break;
  case LOADER_NAMES_NUMBERS:
   columns=COLUMNS_NUMBERS;
   break;
  default:
   columns=COLUMNS_EMAILS;
   break;
 }
 adapter.changeCursor(c, columns);
}

代码示例来源:origin: robolectric/robolectric

@Test
 public void shouldCallOnForceLoad() {
  loader.forceLoad();
  assertThat(onForceLoadCalled).isTrue();
 }
}

代码示例来源:origin: k9mail/k-9

private boolean hasLoadingAttachments() {
  for (Attachment attachment : attachments.values()) {
    Loader loader = loaderManager.getLoader(attachment.loaderId);
    if (loader != null && loader.isStarted()) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: com.uphyca/android-junit3-extension-support-v4

@Override
  public void onLoadComplete(Loader<T> completedLoader, T data) {
    // Shut the loader down
    completedLoader.unregisterListener(this);
    completedLoader.stopLoading();
    completedLoader.reset();
    // Store the result, unblocking the test thread
    queue.add(data);
  }
};

代码示例来源:origin: com.google.android/support-v4

/**
 * Starts an asynchronous load of the Loader's data. When the result
 * is ready the callbacks will be called on the process's main thread.
 * If a previous load has been completed and is still valid
 * the result may be passed to the callbacks immediately.
 * The loader will monitor the source of
 * the data set and may deliver future callbacks if the source changes.
 * Calling {@link #stopLoading} will stop the delivery of callbacks.
 *
 * <p>This updates the Loader's internal state so that
 * {@link #isStarted()} and {@link #isReset()} will return the correct
 * values, and then calls the implementation's {@link #onStartLoading()}.
 *
 * <p>Must be called from the process's main thread.
 */
public final void startLoading() {
  mStarted = true;
  mReset = false;
  mAbandoned = false;
  onStartLoading();
}

代码示例来源:origin: com.google.android/support-v4

void stop() {
  if (DEBUG) Log.v(TAG, "  Stopping: " + this);
  mStarted = false;
  if (!mRetaining) {
    if (mLoader != null && mListenerRegistered) {
      // Let the loader know we're done with it
      mListenerRegistered = false;
      mLoader.unregisterListener(this);
      mLoader.stopLoading();
    }
  }
}

代码示例来源:origin: com.google.android/support-v4

if (mListenerRegistered) {
  mListenerRegistered = false;
  mLoader.unregisterListener(this);
mLoader.reset();

代码示例来源:origin: livroandroid/5ed

@Override
  public void onCancel(DialogInterface dialog) {
    Log.d("livroandroid", "onCancel()");
    // Cancela o loader
    getLoaderManager().getLoader(0).reset();
  }
});

代码示例来源:origin: livroandroid/5ed

@Override
  public void onCancel(DialogInterface dialog) {
    getLoaderManager().getLoader(0).stopLoading();
  }
});

代码示例来源:origin: kingargyle/adt-leanback-support

/**
 * Starts an asynchronous load of the Loader's data. When the result
 * is ready the callbacks will be called on the process's main thread.
 * If a previous load has been completed and is still valid
 * the result may be passed to the callbacks immediately.
 * The loader will monitor the source of
 * the data set and may deliver future callbacks if the source changes.
 * Calling {@link #stopLoading} will stop the delivery of callbacks.
 *
 * <p>This updates the Loader's internal state so that
 * {@link #isStarted()} and {@link #isReset()} will return the correct
 * values, and then calls the implementation's {@link #onStartLoading()}.
 *
 * <p>Must be called from the process's main thread.
 */
public final void startLoading() {
  mStarted = true;
  mReset = false;
  mAbandoned = false;
  onStartLoading();
}

代码示例来源:origin: kingargyle/adt-leanback-support

void stop() {
  if (DEBUG) Log.v(TAG, "  Stopping: " + this);
  mStarted = false;
  if (!mRetaining) {
    if (mLoader != null && mListenerRegistered) {
      // Let the loader know we're done with it
      mListenerRegistered = false;
      mLoader.unregisterListener(this);
      mLoader.stopLoading();
    }
  }
}

代码示例来源:origin: kingargyle/adt-leanback-support

if (mListenerRegistered) {
  mListenerRegistered = false;
  mLoader.unregisterListener(this);
mLoader.reset();

代码示例来源:origin: k9mail/k-9

@Override
public void onLoadFinished(Loader<MessageViewInfo> loader, MessageViewInfo messageViewInfo) {
  if (loader.getId() != DECODE_MESSAGE_LOADER_ID) {
    throw new IllegalStateException("loader id must be message decoder id");
  }
  onDecodeMessageFinished(messageViewInfo);
}

代码示例来源:origin: stackoverflow.com

public class MyFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate():" + mContent);
    Loader loader = getLoaderManager().initLoader(0, null, this);
    loader.forceLoad();
  }   

  @Override
  public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    Log.d(TAG, "onCreateLoader()")  ;
    return new FooLoader(getActivity());
  }

  @Override
  public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
    Log.d(TAG, "onLoadFinished");            
  }

  @Override
  public void onLoaderReset(Loader<Cursor> cursorLoader) {   
  }
}

代码示例来源:origin: fr.avianey/facebook-android-api

@Override
protected void onStartLoading() {
  super.onStartLoading();
  if (cursor != null) {
    deliverResult(cursor);
  }
}

代码示例来源:origin: square/assertj-android

public S isNotStarted() {
  isNotNull();
  assertThat(actual.isStarted()) //
    .overridingErrorMessage("Expected to not be started but was started.") //
    .isFalse();
  return myself;
 }
}

代码示例来源:origin: k9mail/k-9

@Override
public void onLoadFinished(Loader<LocalMessage> loader, LocalMessage message) {
  if (loader.getId() != LOCAL_MESSAGE_LOADER_ID) {
    throw new IllegalStateException("loader id must be message loader id");
  }
  localMessage = message;
  if (message == null) {
    onLoadMessageFromDatabaseFailed();
  } else {
    onLoadMessageFromDatabaseFinished();
  }
}

代码示例来源:origin: com.google.android/support-v4

/**
 * Called when {@link ForceLoadContentObserver} detects a change.  The
 * default implementation checks to see if the loader is currently started;
 * if so, it simply calls {@link #forceLoad()}; otherwise, it sets a flag
 * so that {@link #takeContentChanged()} returns true.
 *
 * <p>Must be called from the process's main thread.
 */
public void onContentChanged() {
  if (mStarted) {
    forceLoad();
  } else {
    // This loader has been stopped, so we don't want to load
    // new data right now...  but keep track of it changing to
    // refresh later if we start again.
    mContentChanged = true;
  }
}

代码示例来源:origin: michal-luszczuk/tomorrow-mvp

/**
 * onStartLoading will be called automatically after loader will be asked for data
 * If object is currently loaded it will be returned with deliverResult() method otherwise
 * forceLoad() method will be called to create it for the first time
 */
@Override
protected void onStartLoading() {
  super.onStartLoading();
  if (objectToRetain != null) {
    deliverResult(objectToRetain);
  } else {
    forceLoad();
  }
}

代码示例来源:origin: square/assertj-android

public S isStarted() {
 isNotNull();
 assertThat(actual.isStarted()) //
   .overridingErrorMessage("Expected to be started but was not started.") //
   .isTrue();
 return myself;
}

相关文章