public void setAdapter(TaskDescriptionAdapter adapter) {
    Log.d(TAG, "adapter.getCount() = " + adapter.getCount());
    mAdapter = adapter;
    mAdapter.registerDataSetObserver(
        new DataSetObserver() {
          public void onChanged() {
            update();
          }

          public void onInvalidated() {
            update();
          }
        });
    DisplayMetrics dm = getResources().getDisplayMetrics();
    int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(dm.widthPixels, MeasureSpec.AT_MOST);
    int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(dm.heightPixels, MeasureSpec.AT_MOST);
    View child = mAdapter.createView(mLinearLayout);
    child.measure(childWidthMeasureSpec, childheightMeasureSpec);
    mNumItemsInOneScreenful =
        (int) FloatMath.ceil(dm.widthPixels / (float) child.getMeasuredWidth());
    addToRecycledViews(child);

    mCellWidth = child.getMeasuredWidth();

    for (int i = 0; i < mNumItemsInOneScreenful - 1; i++) {
      addToRecycledViews(mAdapter.createView(mLinearLayout));
    }
  }
  private void update() {
    for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
      View v = mLinearLayout.getChildAt(i);
      addToRecycledViews(v);
      mAdapter.recycleView(v);
    }
    LayoutTransition transitioner = getLayoutTransition();
    setLayoutTransition(null);

    mLinearLayout.removeAllViews();
    Iterator<View> recycledViews = mRecycledViews.iterator();

    for (int i = mAdapter.getCount() - 1; i >= 0; i--) {
      View old = null;
      if (recycledViews.hasNext()) {
        old = recycledViews.next();
        recycledViews.remove();
        old.setVisibility(VISIBLE);
      }

      final View view = mAdapter.getView(i, old, mLinearLayout);

      if (mFadedEdgeDrawHelper != null) {
        mFadedEdgeDrawHelper.addViewCallback(view);
      }

      OnTouchListener noOpListener =
          new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
              return true;
            }
          };

      view.setOnClickListener(
          new OnClickListener() {
            public void onClick(View v) {}
          });
      // We don't want a click sound when we dimiss recents
      view.setSoundEffectsEnabled(false);

      OnClickListener launchAppListener =
          new OnClickListener() {
            public void onClick(View v) {
              mCallback.handleOnClick(view);
            }
          };

      OnClickListener lockToScreenClickListener =
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              mCallback.handleLockToScreen(view);
            }
          };

      RecentsPanelView.ViewHolder holder = (RecentsPanelView.ViewHolder) view.getTag();
      final View thumbnailView = holder.thumbnailView;
      final View lockToScreenView = holder.lockToScreenView;
      /*OnLongClickListener longClickListener = new OnLongClickListener() {
          public boolean onLongClick(View v) {
              final View anchorView = view.findViewById(R.id.app_description);
              mCallback.handleLongPress(view, anchorView, thumbnailView);
              return true;
          }
      };*/
      thumbnailView.setClickable(true);
      thumbnailView.setOnClickListener(launchAppListener);
      if (lockToScreenView != null) {
        lockToScreenView.setClickable(true);
        lockToScreenView.setOnClickListener(lockToScreenClickListener);
      }
      // thumbnailView.setOnLongClickListener(longClickListener);

      // We don't want to dismiss recents if a user clicks on the app title
      // (we also don't want to launch the app either, though, because the
      // app title is a small target and doesn't have great click feedback)
      final View appTitle = view.findViewById(R.id.app_label);
      appTitle.setContentDescription(" ");
      appTitle.setOnTouchListener(noOpListener);
      mLinearLayout.addView(view);
    }
    setLayoutTransition(transitioner);

    // Scroll to end after initial layout.

    final OnGlobalLayoutListener updateScroll =
        new OnGlobalLayoutListener() {
          public void onGlobalLayout() {
            mLastScrollPosition = scrollPositionOfMostRecent();
            scrollTo(mLastScrollPosition, 0);
            final ViewTreeObserver observer = getViewTreeObserver();
            if (observer.isAlive()) {
              observer.removeOnGlobalLayoutListener(this);
            }
          }
        };
    getViewTreeObserver().addOnGlobalLayoutListener(updateScroll);
  }