Java Code Examples for android.support.v4.widget.SwipeRefreshLayout#setOnRefreshListener()
The following examples show how to use
android.support.v4.widget.SwipeRefreshLayout#setOnRefreshListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HomePageFragment.java From WeCenterMobile-Android with GNU General Public License v2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View fragmentView = inflater.inflate(R.layout.fragment_homepage, container, false); mActivity = (MainActivity) getActivity(); mNetState = new NetworkState(); mListView = (LoadMoreList) fragmentView .findViewById(R.id.lvHomeListView); mAdapter = new HomePageAdapter(mActivity, R.layout.list_item_homepage, itemDataList); mListView.setAdapter(mAdapter); mListView.setOnLoadMoreListener(this); mSwipeLayout = (SwipeRefreshLayout) fragmentView .findViewById(R.id.swipe_container); mSwipeLayout.setOnRefreshListener(this); // ����ˢ����ɫ��ʽ mSwipeLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); mSwipeLayout.setRefreshing(true); getData(mPage); return fragmentView; }
Example 2
Source File: ListRefreshFragment.java From Douban with GNU General Public License v2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_list_refresh, container, false); mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout); mRefreshLayout.setOnRefreshListener(this); mRefreshLayout.setColorSchemeResources( android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); lv = (ListView) view.findViewById(R.id.lv); lv.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, getData())); return view; }
Example 3
Source File: UnassignedTickets.java From faveo-helpdesk-android-app with Open Software License 3.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (rootView == null) { rootView = inflater.inflate(R.layout.fragment_recycler, container, false); textViewTotalCount= (TextView) rootView.findViewById(R.id.totalcount); swipeRefresh = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefresh); if (InternetReceiver.isConnected()){ swipeRefresh.setRefreshing(true); new FetchFirst(getActivity()).execute(); } swipeRefresh.setColorSchemeResources(R.color.faveo_blue); swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { new FetchFirst(getActivity()).execute(); } }); tv = (TextView) rootView.findViewById(R.id.empty_view); } // ((MainActivity) getActivity()).setActionBarTitle(getString(R.string.unassigned_tickets)); return rootView; }
Example 4
Source File: CalendarPageFragment.java From Bangumi-Android with MIT License | 6 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); adapter = new CardRecyclerAdapter(ctx, data); RecyclerView mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler); mRecyclerView.addItemDecoration(new MarginDecoration(getActivity())); mRecyclerView.setHasFixedSize(true); mRecyclerView.setAdapter(adapter); mSwipeRefresh = (SwipeRefreshLayout) getView().findViewById(R.id.swipe_refresh); mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mSwipeRefresh.setRefreshing(false); } }); mSwipeRefresh.post(new Runnable() { @Override public void run() { mSwipeRefresh.setRefreshing(true); } }); }
Example 5
Source File: SaleActivity.java From Hands-Chopping with Apache License 2.0 | 6 votes |
@Override public void initData(@Nullable Bundle savedInstanceState) { xBanner=(XBanner)findViewById(R.id.xbanner); recyclerView=(RecyclerView)findViewById(R.id.recyclerView); swipeRefreshLayout=(SwipeRefreshLayout)findViewById(R.id.swipeRefreshLayout); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mPresenter.requestSankoSaleGameList(); } }); imgsUrl=new ArrayList<>(); showLoading(); mPresenter.requestSankoSaleGameList(); LinearLayoutManager llm = new LinearLayoutManager(this); llm.setOrientation(LinearLayoutManager.VERTICAL); recyclerView.setLayoutManager(llm); recyclerView.setAdapter(mAdapter); }
Example 6
Source File: AbstractMainActivity.java From monolog-android with MIT License | 6 votes |
private void initBaseLayout() { drawerFragment = (DrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); //Set up the toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false); // Set up the drawer. drawerFragment.setUp(R.id.navigation_drawer, toolbar, (DrawerLayout) findViewById(R.id.drawer_layout)); //swipe refresh layout mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container); mSwipeRefreshLayout.setColorSchemeResources(android.R.color.darker_gray); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { loadStatue(); } }); //fragments switchFragment(mCurFragment); }
Example 7
Source File: Activity_MyComment.java From FoodOrdering with Apache License 2.0 | 6 votes |
private void initView() { mEmptyView=findViewById(R.id.id_empty_view); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(""); TextView toolbarText = (TextView) findViewById(R.id.toolbar_text); toolbarText.setText("我的评价"); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } recyclerView = (EmptyRecyclerView) findViewById(R.id.commentsRecyclerView); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout); swipeRefreshLayout.setOnRefreshListener(this); if (!Util.checkNetwork(Activity_MyComment.this)) { return; } showList(); }
Example 8
Source File: LordFragment.java From MyHearts with Apache License 2.0 | 6 votes |
private void initView(View view) { mImgGroupList = (ImageView) view.findViewById(R.id.img_group_list); mImgGroupList.setOnClickListener(this); mLordRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view); mLordRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 3)); //mLordRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL_LIST)); mLordRecyclerView.setItemAnimator(new DefaultItemAnimator()); mLordAdapter = new LordAdapter(getContext(), mLordDatas); mLordRecyclerView.setAdapter(mLordAdapter); mLordAdapter.setOnItemClickListener((view1, position) -> { Intent intent = new Intent(getContext(), LordDetailActivity.class); intent.putExtra("catgId", mLordDatas.get(position).getId()); intent.putExtra("title", mLordDatas.get(position).getLabel()); startActivity(intent); //Toast.makeText(getContext(), mLordDatas.get(position).getLabel(), Toast.LENGTH_SHORT).show(); }); mLordRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swipeRefresh); mLordRefresh.setColorSchemeColors(Color.RED, Color.BLUE, Color.GREEN); mLordRefresh.setOnRefreshListener(this); }
Example 9
Source File: NewsListFragment.java From SimpleNews with Apache License 2.0 | 6 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_newslist, null); mSwipeRefreshWidget = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_widget); mSwipeRefreshWidget.setColorSchemeResources(R.color.primary, R.color.primary_dark, R.color.primary_light, R.color.accent); mSwipeRefreshWidget.setOnRefreshListener(this); mRecyclerView = (RecyclerView)view.findViewById(R.id.recycle_view); mRecyclerView.setHasFixedSize(true); mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mAdapter = new NewsAdapter(getActivity().getApplicationContext()); mAdapter.setOnItemClickListener(mOnItemClickListener); mRecyclerView.setAdapter(mAdapter); mRecyclerView.addOnScrollListener(mOnScrollListener); onRefresh(); return view; }
Example 10
Source File: BasicListActivity.java From android-recyclerview with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(com.jayway.recyclerview.R.layout.activity_recycler_view_example); mRecyclerView = (RecyclerView) findViewById(com.jayway.recyclerview.R.id.recyclerview); mRecyclerView.setLayoutManager(getLayoutManager()); mRecyclerView.setAdapter(getAdapter()); mRecyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL)); // This part is just added to show the animations. final SwipeRefreshLayout swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe); swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { swipeView.setRefreshing(true); swipeView.postDelayed(new Runnable() { @Override public void run() { swipeView.setRefreshing(false); addData(10, 5); } }, 3000); } }); getSupportActionBar().setTitle("Basic List"); }
Example 11
Source File: TransactionsActivity.java From trust-wallet-android-source with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { AndroidInjection.inject(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_transactions); toolbar(); setTitle(getString(R.string.unknown_balance_with_symbol)); setSubtitle(""); initBottomNavigation(); dissableDisplayHomeAsUp(); adapter = new TransactionsAdapter(this::onTransactionClick); SwipeRefreshLayout refreshLayout = findViewById(R.id.refresh_layout); systemView = findViewById(R.id.system_view); RecyclerView list = findViewById(R.id.list); list.setLayoutManager(new LinearLayoutManager(this)); list.setAdapter(adapter); systemView.attachRecyclerView(list); systemView.attachSwipeRefreshLayout(refreshLayout); viewModel = ViewModelProviders.of(this, transactionsViewModelFactory) .get(TransactionsViewModel.class); viewModel.progress().observe(this, systemView::showProgress); viewModel.error().observe(this, this::onError); viewModel.defaultNetwork().observe(this, this::onDefaultNetwork); viewModel.defaultWalletBalance().observe(this, this::onBalanceChanged); viewModel.defaultWallet().observe(this, this::onDefaultWallet); viewModel.transactions().observe(this, this::onTransactions); refreshLayout.setOnRefreshListener(viewModel::fetchTransactions); }
Example 12
Source File: SWMTFragment.java From Girls with Apache License 2.0 | 5 votes |
@Override protected void initView() { mSwipeRefreshLayout = (SwipeRefreshLayout) context.findViewById(R.id.sw_layout); mRecyclerView = (RecyclerView) context.findViewById(R.id.receiverview); mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary); mSwipeRefreshLayout.setOnRefreshListener(this); }
Example 13
Source File: HomeFragment.java From NHentai-android with GNU General Public License v3.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) { View view = inflater.inflate(R.layout.fragment_home, container, false); mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout); mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view); mLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setHasFixedSize(true); mBooks = new ArrayList<>(); mAdapter = new BookListRecyclerAdapter(mRecyclerView, mBooks); setRecyclerViewAdapter(mAdapter); mSwipeRefreshLayout.setColorSchemeResources( R.color.deep_purple_500, R.color.pink_500, R.color.orange_500, R.color.brown_500, R.color.indigo_500, R.color.blue_500, R.color.teal_500, R.color.green_500 ); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { if (!mSwipeRefreshLayout.isRefreshing()) { mSwipeRefreshLayout.setRefreshing(true); } mBooks = new ArrayList<>(); mAdapter = new BookListRecyclerAdapter(mRecyclerView, mBooks); setRecyclerViewAdapter(mAdapter); new PageGetTask().execute(mNowPage = 1); } }); new PageGetTask().execute(mNowPage); return view; }
Example 14
Source File: WebsiteListFragment.java From Gazetti_Newspaper_Reader with MIT License | 5 votes |
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); // Log.d(TAG, "ListFragment in onViewCreated "); mListViewContainer = (SwipeRefreshLayout) getActivity().findViewById(R.id.swipe_container); mListViewContainer.setOnRefreshListener(this); mListViewContainer.setColorScheme(R.color.holo_blue_bright, R.color.holo_orange_light, R.color.holo_green_light, R.color.holo_red_light); mListView = getListView(); mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); mListView.setOnScrollListener(this); headerOnList = getActivity().getLayoutInflater().inflate(R.layout.header_view, null); headerTextView = (TextView) headerOnList.findViewById(R.id.headerTextView); headerOnList.setBackgroundColor(listViewHeaderColor); mListView.addHeaderView(headerOnList); newsAdapter = new NewsAdapter(getActivity(), retainedList); SwingBottomInAnimationAdapter animAdapter = new SwingBottomInAnimationAdapter(newsAdapter); ScaleInAnimationAdapter animAdapterMultiple = new ScaleInAnimationAdapter(animAdapter); animAdapterMultiple.setAbsListView(mListView); mListView.setAdapter(animAdapterMultiple); footerOnList = getActivity().getLayoutInflater().inflate(R.layout.footer_view, null); mListView.addFooterView(footerOnList); mListView.removeFooterView(footerOnList); }
Example 15
Source File: PictureFragment.java From TestChat with Apache License 2.0 | 5 votes |
@Override public void initView() { refresh = (SwipeRefreshLayout) findViewById(R.id.refresh_happy_fragment); display = (RecyclerView) findViewById(R.id.rcv_happy_fragment_display); refresh.setOnRefreshListener(this); // display.addOnScrollListener(new RecyclerView.OnScrollListener() { // @Override // public void onScrolled(RecyclerView recyclerView, int dx, int dy) { // if (dy > 0) { //// 向下滚动 // visibleCount = mStaggeredGridLayoutManager.getChildCount(); // firstVisiblePosition = mStaggeredGridLayoutManager.findFirstVisibleItemPositions(null); // itemCount = mStaggeredGridLayoutManager.getItemCount(); // minFirstVisiblePosition = firstVisiblePosition[0]; // for (int i = 0; i < firstVisiblePosition.length - 1; i++) { // if (firstVisiblePosition[i + 1] < minFirstVisiblePosition) { // minFirstVisiblePosition = firstVisiblePosition[i + 1]; // } // } // if (!isLoading && minFirstVisiblePosition + visibleCount >= itemCount) { // isLoading = true; // onLoadMoreData(currentPage); // } // } // } // }); }
Example 16
Source File: HappyContentFragment.java From TestChat with Apache License 2.0 | 4 votes |
@Override public void initView() { SwipeRefreshLayout refresh = (SwipeRefreshLayout) findViewById(R.id.refresh_happy_fragment); display = (RecyclerView) findViewById(R.id.rcv_happy_fragment_display); refresh.setOnRefreshListener(this); }
Example 17
Source File: MainActivity.java From your-local-weather with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { ((YourLocalWeather) getApplication()).applyTheme(this); super.onCreate(savedInstanceState); locationsDbHelper = LocationsDbHelper.getInstance(this); weatherForecastDbHelper = WeatherForecastDbHelper.getInstance(this); currentWeatherDbHelper = CurrentWeatherDbHelper.getInstance(this); setContentView(R.layout.activity_main); weatherConditionsIcons(); initializeTextView(); initializeWeatherReceiver(); connectionDetector = new ConnectionDetector(MainActivity.this); setTitle( R.string.label_activity_main); /** * Configure SwipeRefreshLayout */ mSwipeRefresh = (SwipeRefreshLayout) findViewById(R.id.main_swipe_refresh); int top_to_padding = 150; mSwipeRefresh.setProgressViewOffset(false, 0, top_to_padding); mSwipeRefresh.setColorSchemeResources(R.color.swipe_red, R.color.swipe_green, R.color.swipe_blue); mSwipeRefresh.setOnRefreshListener(swipeRefreshListener); NestedScrollView main_scroll_view = (NestedScrollView) findViewById(R.id.main_scroll_view); main_scroll_view.setOnTouchListener(new ActivityTransitionTouchListener( null, WeatherForecastActivity.class, this)); updateUI(); /** * Share weather fab */ FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); this.storedContext = this; fab.setOnClickListener(fabListener); checkSettingsAndPermisions(); //startAlarms(); StartAlarmsTask startAlarmsTask = new StartAlarmsTask(); startAlarmsTask.execute(new Integer[0]); }
Example 18
Source File: WeatherActivity.java From FoodOrdering with Apache License 2.0 | 4 votes |
private void initWidget() { contentMian = (ScrollView) findViewById(R.id.content_main); contentMian.setVisibility(View.INVISIBLE); mCurrentAreaTv = (TextView) findViewById(R.id.tv_topCity); mCurrentAreaTv.setText("正在刷新"); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh); swipeRefreshLayout.post(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(true); } }); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refresh(false); } }); mToolbar = (Toolbar) findViewById(R.id.toolbar); mToolbar.setTitle(""); setSupportActionBar(mToolbar); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawLayout); mFirstShowRl = findViewById(R.id.first_show_rl); TypedArray actionbarSizeTypedArray = this.obtainStyledAttributes(new int[]{android.R.attr.actionBarSize}); int h = (int) actionbarSizeTypedArray.getDimension(0, 0); mFirstShowRl.getLayoutParams().height = ScreenUtil.getScreenHeight(this) - h - ScreenUtil.getStatusBarHeight(this); // setDrawerLayout();//加载侧滑栏菜单 setRealWeather(); setForeCast(); setWind(); setAqi(); setSunRiseView(); setZhiShu(); }
Example 19
Source File: CircleFriendsActivity.java From MyHearts with Apache License 2.0 | 4 votes |
@Override public void initView() { eventid = getIntent().getStringExtra("eventid"); mCommentCount = Integer.parseInt(getIntent().getStringExtra("commentCount")); totalPage = mCommentCount / 30 + 1; this.mLlrote = (LinearLayout) findViewById(R.id.ll_rote); this.mRecomment = (LinearLayout) findViewById(R.id.re_comment); this.mRecyclerview = (RecyclerView) findViewById(R.id.recycler_view); mRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh); mRefreshLayout.setColorSchemeColors(Color.YELLOW, Color.RED, Color.BLUE, Color.GREEN); mRefreshLayout.post(() -> mRefreshLayout.setRefreshing(true)); mRefreshLayout.setOnRefreshListener(this); FullyLinearLayoutManager manager = new FullyLinearLayoutManager(this) { @Override public boolean canScrollVertically() { return false; } }; mRecyclerview.setLayoutManager(manager); mRecyclerview.setItemAnimator(new SlideInOutTopItemAnimator(mRecyclerview)); mCommentAdapter = new CircleFriendsCommentAdapter(this, mCircleFriendsComments); mRecyclerview.setAdapter(mCommentAdapter); // //滑动到底部自动加载更多(如果后面还有数据的话) // mRecyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() { // @Override // public void onScrollStateChanged(RecyclerView recyclerView, int newState) { // super.onScrollStateChanged(recyclerView, newState); // // int lastVisiableItemPosition = manager.findLastVisibleItemPosition(); // int itemNum = manager.getItemCount(); // if (lastVisiableItemPosition + 1 == manager.getItemCount()) { // if (!isLoading) { // isLoading = true; // CustomPrograss.show(CircleFriendsActivity.this, // getResources().getString(R.string.loading), false, null); // new Handler().postDelayed(() -> { // getMoreData(); // isLoading = false; // CustomPrograss.disMiss(); // // mMemberAdapter.notifyItemRemoved(mMemberAdapter.getItemCount()); // }, 3000); // } // } // } // }); this.mTvviewcount = (TextView) findViewById(R.id.tv_view_count); this.mIvcomment = (ImageView) findViewById(R.id.iv_comment); this.mTvcommentcount = (TextView) findViewById(R.id.tv_comment_count); this.mIvtype = (ImageView) findViewById(R.id.iv_type); this.mNineGrid = (NineGridView) findViewById(R.id.nineGrid); this.mTvcontent = (TextView) findViewById(R.id.tv_content); this.mImagegender = (ImageView) findViewById(R.id.image_gender); this.mTvtime = (TextView) findViewById(R.id.tv_time); this.mTvname = (TextView) findViewById(R.id.tv_name); this.mIvtour = (ImageView) findViewById(R.id.iv_tour); this.mIcBack = (ImageView) findViewById(R.id.ic_back); this.mIcReport = (ImageView) findViewById(R.id.ic_report); mScrollView = (MyScrollview) findViewById(R.id.scrollView); mScrollView.setVisibility(View.INVISIBLE); mScrollView.setOnZdyScrollViewListener(() -> { //加载更多数据 CustomPrograss.show(CircleFriendsActivity.this, getResources().getString(R.string.loading), false, null); new Handler().postDelayed(() -> getMoreData(),1000); }); }
Example 20
Source File: ContributionsView.java From Slide with GNU General Public License v3.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false); final RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content)); final PreCachingLayoutManager mLayoutManager; mLayoutManager = new PreCachingLayoutManager(getContext()); rv.setLayoutManager(mLayoutManager); rv.setItemViewCacheSize(2); v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE); final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout); mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(id, getActivity())); //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned. //So, we estimate the height of the header in dp mSwipeRefreshLayout.setProgressViewOffset(false, Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM); mSwipeRefreshLayout.post(new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(true); } }); if (where.equals("saved") && getActivity() instanceof Profile) posts = new ContributionPostsSaved(id, where, ((Profile) getActivity()).category); else posts = new ContributionPosts(id, where); //noinspection StringEquality if (where == "hidden") adapter = new ContributionAdapter(getActivity(), posts, rv, true); else adapter = new ContributionAdapter(getActivity(), posts, rv); rv.setAdapter(adapter); posts.bindAdapter(adapter, mSwipeRefreshLayout); //TODO catch errors mSwipeRefreshLayout.setOnRefreshListener( new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { posts.loadMore(adapter, id, true); //TODO catch errors } } ); rv.addOnScrollListener(new ToolbarScrollHideHandler((Toolbar) getActivity().findViewById(R.id.toolbar), getActivity().findViewById(R.id.header)) { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); visibleItemCount = rv.getLayoutManager().getChildCount(); totalItemCount = rv.getLayoutManager().getItemCount(); if (rv.getLayoutManager() instanceof PreCachingLayoutManager) { pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition(); } else { int[] firstVisibleItems = null; firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems); if (firstVisibleItems != null && firstVisibleItems.length > 0) { pastVisiblesItems = firstVisibleItems[0]; } } if (!posts.loading) { if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount && !posts.nomore) { posts.loading = true; posts.loadMore(adapter, id, false); } } } }); return v; }