I made a query to pull only 6 itens from database inside a RecyclerView, but at this time I can only orderByChild, limitToFirst or last. Everything is working fine but...
I'd like to put Random itens inside the Recyclerview every time I refresh the activity.
How can I put random data inside RecyclerView? Firebase does not have a special Random query. Is there any other way to do it?
Here is 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);
}
}
Aucun commentaire:
Enregistrer un commentaire