Forked from mSobhy90/AbstractRecyclerViewFooterAdapter.java
Last active
October 29, 2015 18:15
-
-
Save hardikamal/b73a9471a8f1261b49fc to your computer and use it in GitHub Desktop.
An example of how-to implement an infinite scrolling adapter for a RecyclerView, with a ProgressBar footer. Blog post can be found here: http://msobhy.me/2015/09/05/infinite_scrolling_recyclerview/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MyActivity extends ActionBarActivity { | |
| @InjectView(R.id.myRecyclerView) | |
| RecyclerView mRecyclerView; | |
| RecyclerViewFooterAdapterImpl mAdapter; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(getLayoutResource()); | |
| mRecyclerView.setHasFixedSize(true); | |
| RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this); | |
| mRecyclerView.setLayoutManager(mLayoutManager); | |
| mAdapter = new RecyclerViewFooterAdapterImpl(mRecyclerView, vehicleModelEngines, new OnLoadMoreListener() { | |
| @Override | |
| public void onLoadMore() { | |
| callEndpointForPage(vehicleMakeModel.getId(), new Runnable() { | |
| @Override | |
| public void run() { | |
| mAdapter.removeItem(null); // don't forget to remove the progress bar representative value | |
| updateAdapter(false); | |
| } | |
| }); | |
| } | |
| }, this, currentSortType); | |
| mRecyclerView.setAdapter(mAdapter); | |
| } | |
| private void updateAdapter(boolean shouldGoUp) { | |
| List<MyModelType> myDataSet = new ArrayList<>(MyModelType); | |
| mAdapter.resetItems(myDataSet, currentSortType); | |
| if (shouldGoUp) { | |
| if (mAdapter.getFirstVisibleItem() <= 50) { | |
| mRecyclerView.smoothScrollToPosition(0); | |
| } else { | |
| mRecyclerView.scrollToPosition(0); | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <ProgressBar | |
| android:id="@+id/progressBar" | |
| xmlns:android="http://schemas.android.com/apk/res/android" | |
| android:layout_width="match_parent" | |
| android:layout_height="wrap_content" | |
| android:layout_gravity="center" | |
| android:padding="@dimen/space_medium"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment