@Override public void onClick(View v) { if (refreshing) return; Animation operatingAnim = AnimationUtils.loadAnimation(getActivity(), R.anim.refresh_route); LinearInterpolator lin = new LinearInterpolator(); operatingAnim.setInterpolator(lin); if (operatingAnim != null) { v.startAnimation(operatingAnim); } swipeRefreshLayout.setRefreshing(true); mListView.post( new Runnable() { @Override public void run() { mListView.smoothScrollToPosition(0); } }); mListView.postDelayed( new Runnable() { @Override public void run() { onRefresh(); } }, 800); }
@Override public <T> void onQueryReturned(int pos, String url) { foodItems.get(pos).setPhotoUrl(url); mRecyclerView.post( new Runnable() { @Override public void run() { adapter.notifyDataSetChanged(); } }); }
/** * Register a RecyclerView to the current MaterialViewPagerAnimator Listen to * RecyclerView.OnScrollListener so give to $[onScrollListener] your RecyclerView.OnScrollListener * if you already use one For loadmore or anything else * * @param recyclerView the scrollable * @param onScrollListener use it if you want to get a callback of the RecyclerView */ public void registerRecyclerView( final RecyclerView recyclerView, final RecyclerView.OnScrollListener onScrollListener) { if (recyclerView != null) { scrollViewList.add(recyclerView); // add to the scrollable list yOffsets.put( recyclerView, recyclerView.getScrollY()); // save the initial recyclerview's yOffset (0) into hashmap // only necessary for recyclerview // listen to scroll recyclerView.addOnScrollListener( new RecyclerView.OnScrollListener() { boolean firstZeroPassed; @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); if (onScrollListener != null) onScrollListener.onScrollStateChanged(recyclerView, newState); } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); if (onScrollListener != null) onScrollListener.onScrolled(recyclerView, dx, dy); int yOffset = yOffsets.get(recyclerView); yOffset += dy; yOffsets.put(recyclerView, yOffset); // save the new offset // first time you get 0, don't share it to others scrolls if (yOffset == 0 && !firstZeroPassed) { firstZeroPassed = true; return; } // only if yOffset changed if (isNewYOffset(yOffset)) onMaterialScrolled(recyclerView, yOffset); } }); recyclerView.post( new Runnable() { @Override public void run() { setScrollOffset(recyclerView, lastYOffset); } }); } }
@Override public void onClick(View v) { swipeRefreshLayout.setRefreshing(true); mListView.post( new Runnable() { @Override public void run() { mListView.smoothScrollToPosition(0); } }); mListView.postDelayed( new Runnable() { @Override public void run() { onRefresh(); } }, 800); }
public void onEventMainThread(MainActivity.BottomItemRefreshEvent event) { if (event.bottomIndex == 2 && !refreshing && mListView != null && mListView.getVisibility() == View.VISIBLE) { swipeRefreshLayout.setRefreshing(true); mListView.post( new Runnable() { @Override public void run() { mListView.smoothScrollToPosition(0); } }); mListView.postDelayed( new Runnable() { @Override public void run() { onRefresh(); } }, 800); } }