// suppress this error message to be able to use spaces in higher api levels
  @SuppressLint("NewApi")
  public void refresh() {

    if (mAdapter == null) {
      mAdapter = new StackAdapter(mContext, mStacks, mSwipeable);
      if (mListView != null) {
        mListView.setAdapter(mAdapter);
      } else if (mTableLayout != null) {
        TableRow tr = null;
        for (int i = 0; i < mAdapter.getCount(); i += mColumnNumber) {
          // add a new table row with the current context
          tr = new TableRow(mTableLayout.getContext());
          tr.setOrientation(TableRow.HORIZONTAL);
          tr.setLayoutParams(
              new TableRow.LayoutParams(
                  TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
          // add as many cards as the number of columns indicates per row
          for (int j = 0; j < mColumnNumber; j++) {
            if (i + j < mAdapter.getCount()) {
              View card = mAdapter.getView(i + j, null, tr);
              if (card.getLayoutParams() != null) {
                card.setLayoutParams(
                    new TableRow.LayoutParams(
                        card.getLayoutParams().width, card.getLayoutParams().height, 1f));
              } else {
                card.setLayoutParams(
                    new TableRow.LayoutParams(
                        TableRow.LayoutParams.MATCH_PARENT,
                        TableRow.LayoutParams.WRAP_CONTENT,
                        1f));
              }
              tr.addView(card);
            }
          }
          mTableLayout.addView(tr);
        }
        if (tr != null) {
          // fill the empty space with spacers
          for (int j = mAdapter.getCount() % mColumnNumber; j > 0; j--) {
            View space = null;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
              space = new Space(tr.getContext());
            } else {
              space = new View(tr.getContext());
            }
            space.setLayoutParams(
                new TableRow.LayoutParams(
                    TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
            tr.addView(space);
          }
        }
      }
    } else {
      mAdapter.setSwipeable(mSwipeable); // in case swipeable changed;
      mAdapter.setItems(mStacks);
    }
  }
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mQuickReturnView.setText("Default");
    mListView.addHeaderView(mHeader);

    // adapter o day
    String[] array =
        new String[] {
          "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android",
          "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android"
        };
    mListView.setAdapter(
        new ArrayAdapter<String>(getActivity(), R.layout.list_item, R.id.text1, array));

    mListView
        .getViewTreeObserver()
        .addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                mQuickReturnHeight = mQuickReturnView.getHeight();
                mListView.computeScrollY();
                mCachedVerticalScrollRange = mListView.getListHeight();
              }
            });

    mListView.setOnScrollListener(
        new OnScrollListener() {
          @SuppressLint("NewApi")
          @Override
          public void onScroll(
              AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            mScrollY = 0;
            int translationY = 0;

            if (mListView.scrollYIsComputed()) {
              mScrollY = mListView.getComputedScrollY();
            }
            Log.e("------", mPlaceHolder.getTop() + "");
            int rawY =
                mPlaceHolder.getTop()
                    - Math.min(mCachedVerticalScrollRange - mListView.getHeight(), mScrollY);

            switch (mState) {
              case STATE_OFFSCREEN:
                if (rawY <= mMinRawY) {
                  mMinRawY = rawY;
                } else {
                  mState = STATE_RETURNING;
                }
                translationY = rawY;
                break;

              case STATE_ONSCREEN:
                if (rawY < -mQuickReturnHeight) {
                  mState = STATE_OFFSCREEN;
                  mMinRawY = rawY;
                }
                translationY = rawY;
                break;

              case STATE_RETURNING:
                translationY = (rawY - mMinRawY) - mQuickReturnHeight;
                if (translationY > 0) {
                  translationY = 0;
                  mMinRawY = rawY - mQuickReturnHeight;
                }

                if (rawY > 0) {
                  mState = STATE_ONSCREEN;
                  translationY = rawY;
                }

                if (translationY < -mQuickReturnHeight) {
                  mState = STATE_OFFSCREEN;
                  mMinRawY = rawY;
                }
                break;
            }

            /** this can be used if the build is below honeycomb * */
            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
              anim = new TranslateAnimation(0, 0, translationY, translationY);
              anim.setFillAfter(true);
              anim.setDuration(0);
              mQuickReturnView.startAnimation(anim);
            } else {
              mQuickReturnView.setTranslationY(translationY);
            }
          }

          @Override
          public void onScrollStateChanged(AbsListView view, int scrollState) {}
        });
  }