Android tutorial

Android SeekBar Example

Hii Everyone in this tutorial I am sharing how to use a SeekBar in Android, a Seekbar is a ProgressBar elements extension that allows the selection of integer values using a natural user interface. SeekBar has a thumb that can be slid in order to choose a value between 0 and some maximum that can be set from the developer.

Working With Android SeekBar Example

Step 1: First one to  Start Android Studio

Step 2 :  Seconds step to Create a New Project Project ClickOn  ==> File  ==> NEW ==> New Project

Step 3: After create on your project open your java file and XML file and you can just copy the code and paste on your file and run your project.

Step 4: Open Your activity_home.XML and add these code

<RelativeLayout xmlns:android=""
    tools:context="com.codeplayon.seekbar.MainActivity" >




Step 5: Open your file and used this code.

package com.codeplayon.seekbar;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity{

     private SeekBar seekBar;
     private TextView textView;

     protected void onCreate(Bundle savedInstanceState) {
      // Initialize the textview with '0'.
      textView.setText("Covered: " + seekBar.getProgress() + "/" + seekBar.getMax());
      seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
          int progress = 0; 

          public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
              progress = progresValue;
              Toast.makeText(getApplicationContext(), "Changing seekbar's progress", Toast.LENGTH_SHORT).show();

          public void onStartTrackingTouch(SeekBar seekBar) {
              Toast.makeText(getApplicationContext(), "Started tracking seekbar", Toast.LENGTH_SHORT).show();

         public void onStopTrackingTouch(SeekBar seekBar) {
              textView.setText("Covered: " + progress + "/" + seekBar.getMax());
              Toast.makeText(getApplicationContext(), "Stopped tracking seekbar", Toast.LENGTH_SHORT).show();

     // A private method to help us initialize our variables.

     private void initializeVariables() {
         seekBar = (SeekBar) findViewById(;
         textView = (TextView) findViewById(;

Basically SeekBar.OnSeekBarChangeListener is a public static interface that is used to listen to the SeekBar events, so we have to confirm our Activity in order to implement it. This could be done either in the class definition ( public class MainActivity extends Activity implements OnSeekBarChangeListener ) or in the way line 25 shows. Of course, both ways are acceptable and allow us to override OnSeekBarChangeListener‘s methods:

  1. onProgressChanged: notification that the progress level has changed.
  2. onStartTrackingTouch: notification that the user has started a touch gesture.
  3. onStopTrackingTouch: notification that the user has finished a touch gesture.