Search code examples
javaandroidratingbar

How to take rating value from user in a dialog box in android?


I had the query of how can we take the rating value from the user . I have know the onratingbarlistener . But since the code below is used while prompting user with the dialog box. I would appreciate to hear valuable feedbacks or suggestions.

@Override
                        public void onCompleted(Exception e, ImageView result)
                        {
                            spinner.setVisibility(View.GONE);
                            drivername.setTypeface(tf);
                            vehiclenumber.setTypeface(tf);
                            info.setVisibility(View.VISIBLE);
                            ratingBar.setRating(4.5f);
                        }

Solution :

public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromTouch) {
   final int numStars = ratingBar.getNumStars();
   ratingBar.getRating() ;
   final float ratingBarStepSize = ratingBar.getStepSize();
}

Solution

  • ratingBar.getRating(); //Get Rating Bar Value

    When you want to get the rating value when changed

    public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromTouch) {
       final int numStars = ratingBar.getNumStars();
       ratingBar.getRating() ;
       final float ratingBarStepSize = ratingBar.getStepSize();
    }