In this tutorial we’ll implement a SeekBar and a RatingBar in our android application. Before we jump onto the implementation let’s define them and discuss their usage.

Android SeekBar

A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right thereby allowing user to change the values of the components it’s attached to. Its usages includes device brightness control and volume control.

Similar to the ProgressBar, it uses two properties that are android:max and android:progress.

The SeekBar.OnSeekBarChangeListener interface provides methods to perform event handling callbacks for SeekBar. The methods include:

  • onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) : It’s used to notify any change in the level of SeekBar.
  • onStartTrackingTouch(SeekBar seekBar) : It’s used to notify that the user has started a touch gesture.
  • onStopTrackingTouch(SeekBar seekBar) : It’s used to notify that the user has finished a touch gesture

Android RatingBar

Android RatingBar is used to get the rating from the user. The Rating is returned as a floating-point number.

Following are the important attributes of a RatingBar.

  • android:numStars : The number of stars to show in the RatingBar
  • android:stepSize : The step size of the rating. A size of 0.5 implies half ratings can be set (such as 3.5)
  • android:isIndicator : Whether this rating bar is an indicator that indicates the total number of ratings and is non-changeable by the user
  • style=”?android:attr/ratingBarStyleSmall” : Creates small indicator RatingBar style

The getRating() method of RatingBar returns the rating number.
OnRatingBarChangeListener interface is implemented and the following method needs to be overridden:

In this tutorial we’ll display a SeekBar along with a TextView to show the corresponding value from the SeekBar at any given time and a RatingBar with the rating displayed in a toast.

Project Structure



The activity_main.xml layout contains a SeekBar, RatingBar and a TextView as shown in the xml code below:

The is given below:

The method onStartTrackingTouch() is used to perform any task when the user starts dragging the SeekBar. In our case it’s empty. A Toast represents the new rating value obtained from the RatingBar.

Below is our application running in android emulator.
This brings an end to this tutorial. You can download the final Android SeekBar and RatingBar Project from the link given below.

By admin

Leave a Reply