Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get android seekbar value and display it on screen

Tags:

java

android

I'm trying to get the value of the seek bar whenever it changes and display it underneath. I'm using the onclick method on my seekbar to call this method.

public void getNumber(View view)  {     SeekBar seek = (SeekBar) findViewById(R.id.seekBar1);     int seekValue = seek.getProgress();     String x = "Value: " + Integer.toString(seekValue);     ((TextView) findViewById(R.id.level)).setText(x); } 
like image 508
user2154475 Avatar asked Mar 10 '13 19:03

user2154475


People also ask

How can I get SeekBar value?

The SeekBar class is a subclass of ProgressBar , which contains a getProgress() method. Calling PRICEbar. getProgress() will return the value you are looking for.

How do I manage SeekBar on android?

A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys. Placing focusable widgets to the left or right of a SeekBar is discouraged.

How do I SeekBar progress?

You are looking for the method getProgress() of the ProgressBar class as SeekBar is a subclass of ProgressBar . So basically it would be something like that. int value = seekBar. getProgress();

How do I start SeekBar on android?

Step1: Create a new project. After that, you will have java and XML file. Step2: Open your xml file and add a SeekBar and TextView for message as shown below, max attribute in SeekBar define the maximum it can take. Assign ID to SeekBar And TextView.


1 Answers

Here some extra help:

import android.app.Activity;  import android.os.Bundle;  import android.widget.SeekBar;  import android.widget.TextView;   public class AndroidSeekBar extends Activity {     /** Called when the activity is first created. */     @Override     public void onCreate(Bundle savedInstanceState)         super.onCreate(savedInstanceState);         setContentView(R.layout.main);          SeekBar seekBar = (SeekBar)findViewById(R.id.seekbar);         final TextView seekBarValue = (TextView)findViewById(R.id.seekbarvalue);          seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){      @Override     public void onProgressChanged(SeekBar seekBar, int progress,       boolean fromUser) {      // TODO Auto-generated method stub      seekBarValue.setText(String.valueOf(progress));     }      @Override     public void onStartTrackingTouch(SeekBar seekBar) {      // TODO Auto-generated method stub     }      @Override     public void onStopTrackingTouch(SeekBar seekBar) {      // TODO Auto-generated method stub     }         });     }  }  

use the OnProgressChanged event to check the progress of the seekbar, you can return that int to use it somewhere else in your app.

like image 95
Max Avatar answered Oct 14 '22 02:10

Max