Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update SeekBar not firing OnSeekBarChangeListener?

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?

like image 959
dmitru Avatar asked Jan 22 '14 22:01

dmitru


People also ask

How do I change the progress of a SeekBar?

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.

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.

How do I get SeekBar to automatically move on songs?

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.


1 Answers

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-

like image 69
Marco Avatar answered Sep 28 '22 15:09

Marco