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); }
The SeekBar class is a subclass of ProgressBar , which contains a getProgress() method. Calling PRICEbar. getProgress() will return the value you are looking for.
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.
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();
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With