コード例 #1
0
 @Override
 public void run() {
   recyclerView.setVisibility(View.VISIBLE);
   adapter.notifyItemInserted(adapter.getItemCount() - 1);
   recyclerView.smoothScrollToPosition(adapter.getItemCount() - 1);
   ejer.indholdFøjetTilTrin(trin);
 }
コード例 #2
0
ファイル: MediaFragment.java プロジェクト: MEXXIO/impression
 public final void jumpToTop(boolean animateChange) {
   if (animateChange) {
     // stopAnimation();
     mRecyclerView.smoothScrollToPosition(0);
   } else {
     mRecyclerView.scrollToPosition(0);
   }
 }
コード例 #3
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    NumberPickerDialog dialog;
    switch (item.getItemId()) {
      case R.id.action_add:
        dialog = new NumberPickerDialog(getActivity());
        dialog.setTitle("Position to Add");
        dialog.setPickerRange(0, mAdapter.getItemCount() - 1);
        dialog.setOnNumberSelectedListener(
            new NumberPickerDialog.OnNumberSelectedListener() {
              @Override
              public void onNumberSelected(int value) {
                mAdapter.addItem(value);
              }
            });
        dialog.show();

        return true;
      case R.id.action_remove:
        dialog = new NumberPickerDialog(getActivity());
        dialog.setTitle("Position to Remove");
        dialog.setPickerRange(0, mAdapter.getItemCount() - 1);
        dialog.setOnNumberSelectedListener(
            new NumberPickerDialog.OnNumberSelectedListener() {
              @Override
              public void onNumberSelected(int value) {
                mAdapter.removeItem(value);
              }
            });
        dialog.show();

        return true;
      case R.id.action_empty:
        mAdapter.setItemCount(0);
        return true;
      case R.id.action_small:
        mAdapter.setItemCount(5);
        return true;
      case R.id.action_medium:
        mAdapter.setItemCount(25);
        return true;
      case R.id.action_large:
        mAdapter.setItemCount(196);
        return true;
      case R.id.action_scroll_zero:
        mRecyclerView.scrollToPosition(0);
        return true;
      case R.id.action_smooth_zero:
        mRecyclerView.smoothScrollToPosition(0);
        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }
コード例 #4
0
 @Override
 public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
   //            super.onScrollStateChanged(recyclerView, newState);
   try {
     switch (newState) {
       case RecyclerView.SCROLL_STATE_DRAGGING:
         if (isScrollAble) {
           offsetX = 0;
           isScrollAble = false;
         }
         break;
       case RecyclerView.SCROLL_STATE_SETTLING:
         break;
       case RecyclerView.SCROLL_STATE_IDLE:
         if (!isScrollAble) {
           if (Math.abs(offsetX) > itemWidth / 2) {
             if (offsetX >= 0) {
               recyclerView.smoothScrollToPosition(currentPos + 1);
               currentPos = currentPos + 1;
             } else {
               recyclerView.smoothScrollToPosition(currentPos - 1);
               currentPos = currentPos - 1;
             }
           } else {
             recyclerView.smoothScrollToPosition(currentPos);
           }
           offsetX = 0;
           isScrollAble = true;
         }
         break;
     }
   } catch (Exception e) {
     e.printStackTrace();
     isScrollAble = true;
     currentPos = 0;
     offsetX = 0;
     recyclerView.smoothScrollToPosition(currentPos);
   }
 }
  private void addRefreshItem() {

    if (itemList != null) {
      itemList.add(0, new ItemObject("refreshed two"));
      itemList.add(0, new ItemObject("refreshed one"));
      int insertPos = adapter.hasHeader() ? 1 : 0;
      adapter.notifyItemRangeInserted(insertPos, 2);
      if (!adapter.hasHeader()) {
        recyclerView.smoothScrollToPosition(0);
      }
      onRefreshSucced("refresh succeed");
      return;
    }
    onRefreshFailed("refresh failed");
  }
コード例 #6
0
  @Override
  public void onClick(View v) {
    if (Tools.isFastClick()) {
      return;
    }

    int id = v.getId();

    if (R.id.fb_select_date_history_today == id) {
      popCalendar();
    } else if (R.id.fb_scroll_to_top_history_today == id) {
      // 滚动到顶部
      if (null != mRecyclerView) {
        mRecyclerView.smoothScrollToPosition(0);
        hideFb();
      }
    }
  }
コード例 #7
0
  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    mForecastAdapter.swapCursor(data);

    new SendFirstItemData().execute(data);
    if (mPosition != RecyclerView.NO_POSITION) {
      // If we don't need to restart the loader, and there's a desired position to restore
      // to, do so now.
      mRecyclerView.smoothScrollToPosition(mPosition);
    }

    updateEmptyView();
    //        if (data.getCount() > 0) {
    if (data.getCount() == 0) {
      getActivity().supportStartPostponedEnterTransition();

    } else {
      mRecyclerView
          .getViewTreeObserver()
          .addOnPreDrawListener(
              new ViewTreeObserver.OnPreDrawListener() {
                @Override
                public boolean onPreDraw() {
                  // Since we know we're going to get items, we keep the listener around until
                  // we see Children.
                  if (mRecyclerView.getChildCount() > 0) {
                    mRecyclerView.getViewTreeObserver().removeOnPreDrawListener(this);
                    int itemPosition = mForecastAdapter.getSelectedItemPosition();
                    if (RecyclerView.NO_POSITION == itemPosition) itemPosition = 0;
                    RecyclerView.ViewHolder vh =
                        mRecyclerView.findViewHolderForAdapterPosition(itemPosition);
                    if (null != vh && mAutoSelectView) {
                      mForecastAdapter.selectView(vh);
                    }
                    if (mHoldForTransition) {
                      getActivity().supportStartPostponedEnterTransition();
                    }
                    return true;
                  }
                  return false;
                }
              });
    }
  }
コード例 #8
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == ADD_CODE && resultCode == Activity.RESULT_OK) {
      if (mySchedule == null) {
        mySchedule = new ArrayList<>();
        Timetable obj = (Timetable) data.getSerializableExtra("newTimetable");
        mySchedule.add(obj);
        noData.setVisibility(View.INVISIBLE);
        recyclerView.setVisibility(View.VISIBLE);
        recyclerAdapter = new MyScheduleRecyclerAdapter(mySchedule, ManageMySchedule.this);
        recyclerView.setAdapter(recyclerAdapter);
      } else {
        Timetable obj = (Timetable) data.getSerializableExtra("newTimetable");
        // mySchedule.add(obj);
        recyclerView.smoothScrollToPosition(mySchedule.size());

        recyclerAdapter.addNewItem(obj, mySchedule.size());
      }
    } else if (requestCode == EDIT_CODE && resultCode == Activity.RESULT_OK) {

    }
  }
コード例 #9
0
 public void smoothScrollToPosition(int position) {
   recyclerView.smoothScrollToPosition(position);
 }
コード例 #10
0
 public void scrollToTop() {
   if (mAdapter.getItemCount() > 0) {
     mRecyclerView.smoothScrollToPosition(0);
   }
 }