Android Ratingbar


For feedback & quality purpose from users, we generally use Android RatingBar in our Apps. For using Android RatingBar, we need to add it inside our XML Layout file and from file we can obtain its value when user submits feedback, this will be explained in this tutorial.


DownloadSource Code :


Now Let us work on Project : (Refer – Configuring Existing AndroidStudioProject) RatingBar which you might have downloaded from above or you can follow the scripts below by copying it to implement in your Project. To launch Downloaded project, Extract the zip, copy it into AndroidStudioProjects. Now from Android Studio click open Existing Android Studio Project and select the path to extracted file we just copied in AndroidStudioProjects directory. If Sync SDK path prompt comes just click OK and you are ready to work. If still you get error check for AndroidStudioProjects/RatingBar/app/build.gradle , it will contain different SDK Version. Change it to SDK Version which you have.



1. activity_main.xml : Layout file


Explaining above Code :

  • Line 11 We set total No. of stars, depending upon our requirement.
  • Line 12 Step-Size gives the minimum threshold level we can rate. ( e.g. stepSize = 0.5 even allows half star rating )
  • Line 13 This will make our RatingBar with 2.5 stars selected by default.




Explaining above Code :

  • Line 13-21 We have declared our RatingBar, and linked them with that of (activity_main.xml) XML Layout file.
  • Line 26 We have added ratingChange-Listener to our RatingBar, inside which we have placed a method onRatingChanged, which will be invoked when user makes any rating and Toast on Line-32 will display the RatingBar value.



Final Output :

android RatingBar



Report Errors + Bugs & Become Insider for

We would like to hear you, if you find any error or misspelled phrase while reading our tutorials. By reporting mistakes through email to you could help other peers.