/**
   * Enter/exit search mode. By design, a fragment enters search mode only when it has a non-empty
   * query text, so the mode must be tightly related to the current query. For this reason this
   * method must only be called by {@link #setQueryString}.
   *
   * <p>Also note this method doesn't call {@link #reloadData()}; {@link #setQueryString} does it.
   */
  protected void setSearchMode(boolean flag) {
    if (mSearchMode != flag) {
      mSearchMode = flag;
      setSectionHeaderDisplayEnabled(!mSearchMode);

      if (!flag) {
        mDirectoryListStatus = STATUS_NOT_LOADED;
        getLoaderManager().destroyLoader(DIRECTORY_LOADER_ID);
      }

      if (mAdapter != null) {
        mAdapter.setPinnedPartitionHeadersEnabled(flag);
        mAdapter.setSearchMode(flag);

        mAdapter.clearPartitions();
        if (!flag) {
          // If we are switching from search to regular display, remove all directory
          // partitions after default one, assuming they are remote directories which
          // should be cleaned up on exiting the search mode.
          mAdapter.removeDirectoriesAfterDefault();
        }
        mAdapter.configureDefaultPartition(false, flag);
      }

      if (mListView != null) {
        mListView.setFastScrollEnabled(!flag);
      }
    }
  }
 public void setEnabled(boolean enabled) {
   if (mEnabled != enabled) {
     mEnabled = enabled;
     if (mAdapter != null) {
       if (mEnabled) {
         reloadData();
       } else {
         mAdapter.clearPartitions();
       }
     }
   }
 }
 @Override
 public void onStop() {
   super.onStop();
   mContactsPrefs.unregisterChangeListener();
   mAdapter.clearPartitions();
 }