简体   繁体   中英

Multiple SeekBar's - All display the last SeekBars value

I have multiple SeekBars in a single layout (either 3 on a phone, 8 on a tablet). I have a custom Thumb and Background for them, so they appear as a Scale. There is a listener to detect when the values are changed (one for each of the SeekBars), and if it has the Thumb Drawable is changed to a different colour. This is all working.

What is not working, is setting each SeekBar to a saved value. If I set the first SeekBar, its fine. If I set the second, and the first, they both display the value of the second SeekBar. This is the same if I add in the third, fourth, etc. Below is the code I am using to set the SeekBar values

mSeekBarOne.setProgress(mSavedValues.value1);
mSeekBarTwo.setProgress(mSavedValues.value2);
mSeekBarThree.setProgress(mSavedValues.value3);

I have no idea what is going on here, or how to fix this. I have tried requesting a layout pass on each of the SeekBars after they have been set, does not work.

And finally, when I print out the value of each of the SeekBars, it is actually correct! It is purely a visual issue. Maybe I have missed something in the documentation that multiple SeekBar's (or ProgressBar's) cannot be within a single layout, but I have searched and found nothing on this.

Any help would be greatly appreciated.

EDIT: It would appear this issue only occurs if I change the Thumb Drawable after I have set the progress values on each SeekBar. I change the Thumb Drawable by checking the Progress, and if its different to the original value then set the Thumb Drawable to another one (different color).

Adam

It appears the issue is that the Drawable I was using, was being cached in the class. Because of this, the SeekBar was displaying the position of the Drawable for the last time it was updated, which is the last SeekBar position.

I assume this is a fault of my misunderstanding when caching a Drawable locally, instead of using a different drawable per SeekBar. A better explanation as to why this is the case would help me out a lot, but at least its fixed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM