limitToFirst in Firebase Query Reference not worki

2020-08-01 06:40发布

问题:

Below is my firebase structure:


Code I am using to set the limit to data :

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    connectDetector = new ConnectDetector(getActivity());
    if(connectDetector.getConnection()) {
        alanRef = new Firebase(firebaseURL).child(EventChatActivity.SuperCateName + "/ " + eventDetail.getCategory_name() + "/ " + eventDetail.getEvent_title() + "/ " + EventChatActivity.eventID).child("StadiumChat");
        alanRef.limitToFirst(mPageLimit).startAt(mPageEndOffset);
        userName = MyApp.preferences.getString(MyApp.USER_NAME, null);

    }
}

This code gives me all the child in that specific node.

Please suggest what should be added to set limit to it.


Update:

I have added limit to First then I checked documentation which says set OrderBy also to it.

So in which order should I set to get the proper results.

My URL: https://wazznow-cd155.firebaseio.com/Cricket/%20IPL/%20MI%20vs%20XXR/%20ABC123/StadiumChat.json?limitToFirst=10&orderBy=%22%22&print=pretty

回答1:

manish

limitToFirst will work with orderBy value.please use orderBy with limitToFirst .

please check from below url. https://dinosaur-facts.firebaseio.com/dinosaurs.json?orderBy=%22height%22&limitToFirst=3&print=pretty



回答2:

To apply limit you need to use Query.class.

int mPageEndOffset = 0;
int mPageLimit = 10;
Query alanQuery;

alanRef = new Firebase(firebaseURL).child(EventChatActivity.SuperCateName + "/ " + eventDetail.getCategory_name() + "/ " + eventDetail.getEvent_title() + "/ " + EventChatActivity.eventID).child("StadiumChat");
Query alanQuery = alanRef.limitToFirst(mPageLimit);