简体   繁体   中英

Retrieve ratingbar data from firebase database to display in a post

I have a couple of issues with the firebase database data retrieving:

  1. I am trying to retrieve ratingbar data and display it as a review post in a recyclerview. Sending all data to database has no issues, but retrieving the ratingbar returns an empty ratingbar stars.

  2. My text also does not appear as text the user inputs, it returned as blank spaces, and auth.getUid() returns the key value (something like: HUIDBUWFjnzipqE68HFJBF), and not the username.

  3. My review image also is blank.

What could be the issue? I cannot seem to find the solution. Help appreciated!

code snippets: write review activity: Review newReview = new Review(uid, author, categories, location, district, businessName, reviewData, addressData, starsData, sd);

    Map<String, Object> reviewValues = newReview.toMap();
    Map<String, Object> childUpdates = new HashMap<>();
    childUpdates.put("/reviews/" + key, reviewValues);
    childUpdates.put("/user-reviews/" + author + "/" + key, reviewValues);
    reference.updateChildren(childUpdates);
    reference.keepSynced(true);

    reviewImage.setImageResource(R.drawable.ic_photo);

reviewviewholder:

  public void bindToReview(Review review, View.OnClickListener starClickListener) {
   author.setText(review.author);
   categories.setText(review.categories);
   buss_name.setText(review.businessName);
   buss_address.setText(review.addressData);
   location.setText(review.location);
   district.setText(review.district);
   reviewData.setText(review.reviewData);
   date.setText(review.date);
   likeCount.setText(String.valueOf(review.likeCount));
   starsData.setRating(stars);

    likes.setOnClickListener(starClickListener);
}

reviewadapter:

@SuppressLint("CheckResult")
@Override
public void onBindViewHolder(@NonNull ReviewAdapter.ViewHolder holder, int position) {
    holder.uid.setText(reviewsList.get(position).uid);
    holder.categories.setText(reviewsList.get(position).categories);
    holder.author.setText(reviewsList.get(position).author);
    holder.businessName.setText(reviewsList.get(position).businessName);
    holder.address.setText(reviewsList.get(position).addressData);
    holder.reviewData.setText(reviewsList.get(position).reviewData);
    holder.likes.setText(String.valueOf(reviewsList.get(position).likeCount));
    holder.date.setText(reviewsList.get(position).date);
    holder.stars.setText(String.valueOf(reviewsList.get(position).starsData));

    final RequestOptions requestOptions = new RequestOptions();
    requestOptions.placeholder(R.drawable.image_placeholder);
    Glide.with(mContext).applyDefaultRequestOptions(requestOptions)
            .load(reviewsList.get(position).image).into(holder.reviewImage);


}

i commented out the stars line there as i really not sure how to get the value from the ratingbar.

picture for reference

adding the ratings:

  stars = findViewById(R.id.rating);
    stars.setOnRatingBarChangeListener((ratingBar, rating, fromUser) -> {
        if (fromUser) reference.child("rating").setValue(rating);
    });

    reference.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NotNull DataSnapshot dataSnapshot) {
            if (dataSnapshot != null && dataSnapshot.getValue() != null)  {
                rating = Float.parseFloat(String.valueOf(dataSnapshot.getValue()));
                stars.setRating(rating);
            }
        }

        @Override
        public void onCancelled(@NotNull DatabaseError databaseError) { }
    });

getting the stars the view of the stars

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM