I have a SeekBar with an instance of OnSeekBarChangeListener attached. Each time a user changes the value, it's method onProgressChanged() gets fired. That's fine.
But then I'm trying to update the progress of the SeekBar like this:
seekBar.setProgress(value);
I expect that no events will fire - just SeekBar's progress will change. But onProgressChanged() gets called in this case also.
How can I change the progress of a SeekBar without firing events?
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.
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 is the runnable class. Runnable timerRunnable = new Runnable() { public void run() { // Get mediaplayer time and set the value // This will trigger itself every one second.
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {}
Look at the parameters. You have a boolean fromUser, use it.
if (fromUser) {
.........
.........
}
Doing so code will be execute only when change was initiated by user. If you set seekbar's value from code the event will fire but code won't execute due to the if() statement. Bye. -Marco-
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