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);
}
}
});
}
Firebase has FirebaseRecyclerAdapter for connecting RecyclerView directly to firebase database. See FriendlyChat sample app from google for details: https://github.com/firebase/friendlychat
you can use startAt(), endAt(), and equalTo() method, official link enter link description here
// Find all dinosaurs that are at least three meters tall.
var ref = firebase.database().ref("dinosaurs");
ref.orderByChild("height").startAt(3).on("child_added", function(snapshot) {
console.log(snapshot.key)
});
answered:
https://stackoverflow.com/a/41583467/1429832