Android RatingBar Tutorial – How to create Rating in Android Example

By | April 17, 2019

RatingBar in Android Tutorial Example

What is RatingBar ?

RatingBar is a shown of Rating starts.It can be used to get rating from the user.it is return of floating numbers.Like 2.0,2,3.5,4.5. Ratingbar supports user interaction placing widget to the left to right of the Ratingbar.

Smaller Ratingbar style to used of android : R.attr.ratingBarStyleSmall. And Larger indicator-only : R.attr.ratingBarStyleIndicator.

RatingBar is used to getRating() method to return rating number.

Attributes of RatingBar

android:numStars : Display Number of star show.

android:rating : Set Rating by default.

android:stepSize : The step size of the rating.

Methods of RatingBar

setNumStars : Sets The Number of stars to show in Ratingbar.

setOnRatingBarChangeListener : it is used change rating bar when user change click rating button pressed.

setRating : set the rating.

setStepSize : it is used to sets the step of size in ratingbar.

Implementation of RatingBar

Create activity_main.xml file and write and following this code.

Create MainActivity.java File write the following below code.

Now In this code to Use rating bar and button when user set rating on the ratingbar and click on button to get rating number is display toast.and display ratingbar to use getRating() method it is return of floating number.