I am using a Query to load only 6 Firebase database items in the RecyclerView but so far I can only sort using the orderByChild, limitToFirst or last. Everything is working fine but ...
I want to randomly load items into RecyclerView when activity is loaded.
Is there any way to do this? Firebase, unfortunately, does not have a Random Query, all follow defined orders.
My code:
mDatabase = FirebaseDatabase.getInstance().getReference().child("Category");
query = mDatabase.limitToFirst(6);
@Override
protected void populateViewHolder(final CategoryViewHolder viewHolder, Category model, int position) {
viewHolder.setImage(getApplicationContext(), model.getImagem());
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
});
}
};
mImagesList.setAdapter(firebaseRecyclerAdapter);
My adapter:
public static class CategoryViewHolder extends RecyclerView.ViewHolder {
View mView;
public CategoryViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setImage(Context ctx, String image1) {
ImageView image = (ImageView) mView.findViewById(R.id.photo);
Picasso.with(ctx).load(image1).into(image);
}
}