views:

2319

answers:

1

I'm using SeekBar as a slider because I can't find anything else, but I have to do so much hacky work because it doesn't allow me to set a minimum value or go in between ints. So, any time I need a slider to start at a value other than 0 or return a floating point number, I have to set a max value that doesn't describe the true max value of the control and then divide and/or add/subtract the "progress" value when I read it. Before I finish writing an entire class just to handle converting my slider values, is there a better way? I'm using Android 1.6...is there a slider control in 2.0 or any other documented future release?

+2  A: 

Before I finish writing an entire class just to handle converting my slider values, is there a better way?

Not really. For starters, you really don't want something like SeekBar doing floating-point arithmetic along the way, as most phones lack floating-point support in hardware, so floating-point operations are slow. As to why they didn't allow you to set your own custom minimum, instead of just the maximum, I cannot say.

CommonsWare
For now, I wrote a class that acts like a "view model" with constants and helper methods. I use "offset" constants to add/subtract where the min value would be non-zero, I call the other constants "conversion factors" to multiply and divide to emulate my floats, and I created setters to handle the conversions and offsets from the actual progress values. It's clean looking at the class level, but ugly as sin in theory and more work than I would expect to do. I'll see what the process is for adding custom attributes to derived controls and maybe I can just compose or extend it.
Rich