I need know how to load data dynamically on scrolling with Firebase. If I query data with Firebase, all data must be loaded once time or always data changed. I want load data with Firebase per limit, and after reach this limit, load more data and more and more.
It would basically be like a timeline of Facebook - as a social network.
For example: I want to get the latest records from Firebase at limit 50. After reach this limit, I will download the next 50 data. I would like use RecyclerView
and not FirebaseRecycler
class.
FirebaseRecyclerAdapter not solve my question. Thanks for help. Trully, i need loadind data like facebook timeline of point view layout, and load data Firebase (50 to 50. Download 50 data, reach limit, load more data of bottom layout to 50) of point view Database.
Could you help me?
This works perfectly fine. Infinite-Scroll-Endless-Scrolling-Tutorial
private RecyclerView recyclerView;
boolean userScrolled=false;
private boolean loading = true;
int pastVisiblesItems, visibleItemCount, totalItemCount;
LinearLayoutManager mLayoutManager;
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mLayoutManager = new LinearLayoutManager(MainActivity.this);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
// Implement scroll listener
public void implementScrollListener() {
recyclerView
.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView,
int newState) {
super.onScrollStateChanged(recyclerView, newState);
// If scroll state is touch scroll then set userScrolled
// true
if (newState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
userScrolled = true;
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx,
int dy) {
super.onScrolled(recyclerView, dx, dy);
// Here get the child count, item count and visibleitems
// from layout manager
visibleItemCount = mLayoutManager.getChildCount();
totalItemCount = mLayoutManager.getItemCount();
pastVisiblesItems = mLayoutManager
.findFirstVisibleItemPosition();
// Now check if userScrolled is true and also check if
// the item is end then update recycler view and set
// userScrolled to false
if (userScrolled
&& (visibleItemCount + pastVisiblesItems) == totalItemCount) {
userScrolled = false;
RefreshData(oldestPostId);
}
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With