我正在使用下面的代码通过firebase recyclerview检索我的数据库中的数据。我能够检索所有数据,但它们一次被检索。我希望一次检索少量数据,更多应该是当用户向上滚动时加载。我该怎么做?
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot){
if(dataSnapshot.child("Male").hasChild(user_id)){
query = databaseReference1.child("Female").orderByChild("halls").equalTo(halls2);
query.keepSynced(true);
}
else{
query = databaseReference1.child("Male").orderByChild("halls").equalTo(halls1);
query.keepSynced(true);
}
FirebaseRecyclerAdapter<User, tab1.UserViewholder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<User, tab1.UserViewholder>(
User.class, R.layout.users_row, tab1.UserViewholder.class, query) {
@Override
protected void populateViewHolder(tab1.UserViewholder viewHolder, User model, int position) {
final String postUser_id = getRef(position).getKey();
Log.v("key",postUser_id);
//postUserId = postkey of card
final String user_id = firebaseAuth.getCurrentUser().getUid();
//final Match match = new Match(username, downloadUrl );
viewHolder.setUsername(model.getUsername());
viewHolder.setLevels(model.getLevels());
viewHolder.setDownloadUrl(getActivity().getApplicationContext(), model.getDownloadUrl());
}
};
users2.setAdapter(firebaseRecyclerAdapter);
}
@Override
public void onCancelled(DatabaseError databaseError){
}
});