I am trying to get random items from my firebase database and it almost works, sometimes I only get one or two items when the minimum is 3 and max is 5. Every item has an index and it's getting the items that startAt(startindex) and endAt(startIndex+randomNumber).
Is there any other way to do this other than using an index on each item in the database?
Here is how the code looks now:
randomNumber = getRandomInt(3,5);
listView = (ListView)view.findViewById(R.id.listView);
int startIndex = (int)(Math.random() * childs+1);
adapter = new FirebaseListAdapter<TraningData>(getActivity(),TraningData.class,R.layout.layout_traning_item,ref_1
.orderByChild("index")
.startAt(startIndex)
.endAt(startIndex+randomNumber)) {
@Override
protected void populateView(View view, final TraningData td, int i) {
//Populating over here!
}
};
listView.setAdapter(adapter);
Aucun commentaire:
Enregistrer un commentaire