Increase Decrease number value on seekbar android within define range

How to change numeric value on seek bar go forward and go previous movement in range.

In this tutorial we are creating a seek bar and define a number max range 100 .Now when app user moves the seek bar number value will start increasing itself and when user go back then the define number will automatically starts decreasing. So here is the complete step by step tutorial for Increase Decrease number value on seekbar android within define range.

android-project-download-code-button

Increase Decrease number value on seekbar android within define range.

Code for MainActivity.java file.

 package com.increasedecreasenumberseekbar_android_examples.com;

import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;

public class MainActivity extends Activity {

 TextView Num;
 SeekBar seekbar;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 Num = (TextView)findViewById(R.id.textView1);
 seekbar = (SeekBar)findViewById(R.id.seekbar);
 
 
 seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
 
 @Override
 public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
 
 String seekbarValue = String.valueOf(i);
 
 Num.setText(seekbarValue);
 }

 @Override
 public void onStartTrackingTouch(SeekBar seekBar) {

 }
 @Override
 public void onStopTrackingTouch(SeekBar seekBar) {

 }
 });
 
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.increasedecreasenumberseekbar_android_examples.com.MainActivity" >

 <SeekBar
 android:id="@+id/seekbar"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:max="100" />

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_above="@+id/seekbar"
 android:layout_centerHorizontal="true"
 android:layout_marginBottom="25dp"
 android:text="Large Text"
 android:textAppearance="?android:attr/textAppearanceLarge" />
 
</RelativeLayout>

Screenshot :

Increase Decrease number value on seekbar android within define range

Click here to download Increase Decrease number value on seekbar android within define range project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *