The following is my firebase database structure.
The following is the method that I get the data from firebase database to the recycler view. However, there is an unique id(red oval) in the child part. How can I go after the unique id and filter the data using the key "category"? Also, I want to order them in acensding order but firebase does not provide a method for that. Where can I get the list of data and reverse them? Please give me some helps. Thank you very much.
mFilterDatabse = mDatabase.orderByChild("category").equalTo(categoryResult);
FirebaseRecyclerAdapter<Product, ProductViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Product, ProductViewHolder>(
Product.class,
R.layout.product_row,
ProductViewHolder.class,
mFilterDatabse
) {
@Override
protected void populateViewHolder(ProductViewHolder viewHolder, final Product model, int position) {
Log.d(TAG, "loading view " + position);
final String product_id = getRef(position).getKey();
viewHolder.setProductName(model.getProductName());
viewHolder.setDescription(model.getDescription());
viewHolder.setImage(getApplicationContext(), model.getProductImage());
viewHolder.setUid(model.getUid());
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent productDetailIntent = new Intent();
productDetailIntent.setClass(MainActivity.this, ProductDetailActivity.class);
productDetailIntent.putExtra("product_id", product_id);
Log.d(TAG + " product_id", product_id);
productDetailIntent.putExtra("colorNo", model.getColorNo());
Log.d(TAG + " colorNo", model.getColorNo() + "");
startActivity(productDetailIntent);
}
});
Log.d(TAG, "finish loading view");
}
};
mProductList.setAdapter(firebaseRecyclerAdapter);
firebaseRecyclerAdapter.notifyDataSetChanged();
public static class ProductViewHolder extends RecyclerView.ViewHolder {
View mView;
private Typeface customTypeface = Typeface.createFromAsset(itemView.getContext().getAssets(), FontManager.APP_FONT);
public ProductViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setProductName(String productName) {
TextView product_title = (TextView) mView.findViewById(R.id.p_title);
product_title.setText(productName);
product_title.setTypeface(customTypeface);
}
public void setDescription(String description) {
TextView product_desc = (TextView) mView.findViewById(R.id.p_desc);
product_desc.setText(description);
product_desc.setTypeface(customTypeface);
}
public void setUid(String uid) {
TextView product_username = (TextView) mView.findViewById(R.id.p_username);
product_username.setText(uid);
product_username.setTypeface(customTypeface);
}
public void setImage(final Context ctx, final String image) {
final ImageView post_image = (ImageView) mView.findViewById(R.id.product_image);
Picasso.with(ctx).load(image).networkPolicy(NetworkPolicy.OFFLINE).into(post_image, new Callback() {
@Override
public void onSuccess() {
Log.d(TAG, "image loading success !");
}
@Override
public void onError() {
Log.d(TAG, "image loading error !");
Picasso.with(ctx)
.load(image)
.resize(100, 100)
.centerCrop()
.into(post_image);
}
});
}
}