private void deleteEvent (final Event event, final int position) { final Runnable runnableDelete = () -> event.delete(); handler.postDelayed(runnableDelete,5000); events.remove(position); adapter.notifyItemRemoved(position); Snackbar.make(recyclerView, getString(R.string.event_deleted), Snackbar.LENGTH_SHORT) .setAction(getString(R.string.undo), v -> { handler.removeCallbacks(runnableDelete); event.save(); events.add(position, event); adapter.notifyItemInserted(position); recyclerView.scrollToPosition(position); }) .show(); }
@Override public void onActivityReenter(int resultCode, Intent data) { if (data == null || resultCode != RESULT_OK || !data.hasExtra(Activities.Dribbble.Shot.RESULT_EXTRA_SHOT_ID)) return; // When reentering, if the shared element is no longer on screen (e.g. after an // orientation change) then scroll it into view. final long sharedShotId = data.getLongExtra(Activities.Dribbble.Shot.RESULT_EXTRA_SHOT_ID, -1L); if (sharedShotId != -1L // returning from a shot && adapter.getDataItemCount() > 0 // grid populated && grid.findViewHolderForItemId(sharedShotId) == null) { // view not attached final int position = adapter.getItemPosition(sharedShotId); if (position == RecyclerView.NO_POSITION) return; // delay the transition until our shared element is on-screen i.e. has been laid out postponeEnterTransition(); grid.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int l, int t, int r, int b, int oL, int oT, int oR, int oB) { grid.removeOnLayoutChangeListener(this); startPostponedEnterTransition(); } }); grid.scrollToPosition(position); toolbar.setTranslationZ(-1f); } }
final int minLeft = layoutManager.getDecoratedLeft(target.itemView); if (minLeft <= recyclerView.getPaddingLeft()) { recyclerView.scrollToPosition(toPos); recyclerView.scrollToPosition(toPos); final int minTop = layoutManager.getDecoratedTop(target.itemView); if (minTop <= recyclerView.getPaddingTop()) { recyclerView.scrollToPosition(toPos); recyclerView.scrollToPosition(toPos);
@Override void scrollToPosition(RecyclerView list, int pos) { if (list.getLayoutManager() instanceof LinearLayoutManager) { // Centering item in its parent final LinearLayoutManager manager = (LinearLayoutManager) list.getLayoutManager(); final boolean isHorizontal = manager.getOrientation() == LinearLayoutManager.HORIZONTAL; int offset = isHorizontal ? (list.getWidth() - list.getPaddingLeft() - list.getPaddingRight()) / 2 : (list.getHeight() - list.getPaddingTop() - list.getPaddingBottom()) / 2; final RecyclerView.ViewHolder holder = list.findViewHolderForAdapterPosition(pos); if (holder != null) { final View view = holder.itemView; offset -= isHorizontal ? view.getWidth() / 2 : view.getHeight() / 2; } manager.scrollToPositionWithOffset(pos, offset); } else { list.scrollToPosition(pos); } }
mRecyclerView.scrollToPosition(0);
mRecyclerView.scrollToPosition(0);
private void onPhotosReturned(List<File> returnedPhotos) { photos.addAll(returnedPhotos); imagesAdapter.notifyDataSetChanged(); recyclerView.scrollToPosition(photos.size() - 1); }
void resetScroll() { mBinding.list.scrollToPosition(0); }
@Override public void onNext(List<AppInfo> value) { mAdapter.kw = text; mAdapter.showItems(value); if (!value.isEmpty()) { recyclerView.scrollToPosition(0); } }
@Override public void run() { // Ensure we stay at scroll position 0 so we can see the insertion animation final RecyclerView recyclerView = getRecyclerView(); if (recyclerView.getScrollY() == 0) { recyclerView.scrollToPosition(0); } } };
/** * Refreshes RecyclerView by setting new adapter, * calling invalidate method and scrolling to given position * * @param view RecyclerView to be refreshed * @param adapter adapter with new list of items to be loaded * @param position position to which RecyclerView will be scrolled */ protected void refreshView(RecyclerView view, RecyclerView.Adapter adapter, int position) { view.setAdapter(adapter); view.invalidate(); view.scrollToPosition(position); }
private void scrollToBottom() { int i = Math.max(mLayoutManager.findLastVisibleItemPosition(), mLayoutManager.getPendingScrollPosition()); int count = mAdapter == null ? mStatusAdapter.getItemCount() : mAdapter.getItemCount(); if (i >= count - 2) mRecyclerView.scrollToPosition(count - 1); }
private void reloadListFragment() { adapter.updateItems(true); //noinspection ConstantConditions getSupportActionBar().setTitle(drawerManager.getState().getTreeItem().getName()); binding.itemsRecyclerview.scrollToPosition(0); binding.fabMarkAllAsRead.setSync(false); }
@Override public void onChanged(List<StatusEvent> schedule) { adapter.submitList(schedule); if (selectionEnabled) { int selectedPosition = adapter.getPositionForId(selectedId); if (selectedPosition == RecyclerView.NO_POSITION && adapter.getItemCount() > 0) { // There is no current valid selection, reset to use the first item setSelectedId(adapter.getItemId(0)); selectedPosition = 0; } // Ensure the current selection is visible if (selectedPosition != RecyclerView.NO_POSITION) { getRecyclerView().scrollToPosition(selectedPosition); } // Notify the parent of the current selection to synchronize its state notifyEventSelected(selectedPosition, (selectedPosition == RecyclerView.NO_POSITION) ? null : schedule.get(selectedPosition).getEvent()); } else if (!isListAlreadyShown) { final int position = adapter.getPositionForId(selectedId); if (position != RecyclerView.NO_POSITION) { getRecyclerView().scrollToPosition(position); } } isListAlreadyShown = true; setProgressBarVisible(false); } }
else adapter.setSelection(Math.max(adapter.getSelection() - 1, 0)); mSuggestionsList.scrollToPosition(adapter.getSelection()); return true;
mStatusAdapter.setMessages(messages); if (mRecyclerView != null) mRecyclerView.scrollToPosition(mStatusAdapter.getItemCount() - 1); });
if (other != rule && other.getName().equals(mBasicEntry.mName)) { mBasicEntry.setHasDuplicateError(); mRecyclerView.scrollToPosition(mAdapter.getEntries().indexOf(mBasicEntry)); return false; mRecyclerView.scrollToPosition(mAdapter.getEntries().indexOf(mMatchEntry)); return false;
mAdapter.setMessages(messages.getMessages(), messages.getMessageIds()); if (mRecyclerView != null) mRecyclerView.scrollToPosition(mAdapter.getItemCount() - 1); mLoadOlderIdentifier = messages.getOlder(); });