I am trying to get Endless RecyclerView with progress bar showing at bottom when you are loading data from web service. But faced different problems. May be some one needs this.
My StackOverflow answer. Plesae upvote my answer. if it is helpful in your project. http://stackoverflow.com/questions/31000964/how-to-implement-setonscrolllistener-in-recyclerview/31178493#31178493 I want to show complete example on this.
// use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView mRecyclerView.setHasFixedSize(true);
mLayoutManager =new LinearLayoutManager(this);
// use a linear layout manager mRecyclerView.setLayoutManager(mLayoutManager);
// create an Object for Adapter mAdapter =new DataAdapter(studentList, mRecyclerView);
// set the adapter object to the Recyclerview mRecyclerView.setAdapter(mAdapter); // mAdapter.notifyDataSetChanged();
mAdapter.setOnLoadMoreListener(new OnLoadMoreListener(){ @Override publicvoidonLoadMore(){ //add null , so the adapter will check view_type and show progress bar at bottom studentList.add(null); mAdapter.notifyItemInserted(studentList.size()-1);
handler.postDelayed(new Runnable(){ @Override publicvoidrun(){ // remove progress item studentList.remove(studentList.size()-1); mAdapter.notifyItemRemoved(studentList.size()); //add items one by one int start = studentList.size(); int end = start +20;
for(int i = start +1; i <= end; i++){ studentList.add(new Student("Student "+ i,"AndroidStudent"+ i +"@gmail.com")); mAdapter.notifyItemInserted(studentList.size()); } mAdapter.setLoaded(); //or you can add all at once but do not forget to call mAdapter.notifyDataSetChanged(); } },2000);
} });
}
// load initial data privatevoidloadData(){
for(int i =1; i <=20; i++){ studentList.add(new Student("Student "+ i,"androidstudent"+ i +"@gmail.com"));
// The minimum amount of items to have below your current scroll position // before loading more. privateint visibleThreshold =5; privateint lastVisibleItem, totalItemCount; privateboolean loading; private OnLoadMoreListener onLoadMoreListener;
Android Swipe Layout This will be the most powerful Android swipe UI component In one of my Project, I have a requirement to create a Swiping Layout For RecyclerView. I looked for different Libraries. I found this Great Library Android Swipe Layout. I have tried this Library for RecyclerView. I have done sample Project using this great Library. This Library Supports ListView and GridView also. Thanks to the Author for Creating this useful Library: https://github.com/daimajia/ Library Link : https://github.com/daimajia/AndroidSwipeLayout/ Wiki Page: https://github.com/daimajia/AndroidSwipeLayout/wiki Step: 1 ====== Add dependency to your build.gradle file 1 2 3 4 dependencies { compile 'com.daimajia.swipelayout:library:1.2.0@aar' } Step: 2 ====== Create a row for RecyclerView using SwipeLayout 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60...
Comments
Post a Comment