Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
123 views
in Technique[技术] by (71.8m points)

java - 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

question from:https://stackoverflow.com/questions/65890884/retrieve-ratingbar-data-from-firebase-database-to-display-in-a-post

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...