Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slider control in Android...is SeekBar really my best/only option?

Tags:

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?

like image 910
Rich Avatar asked Nov 19 '09 19:11

Rich


People also ask

What is the use of SeekBar in Android?

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. Clients of the SeekBar can attach a SeekBar.

How to get current value of SeekBar in Android?

The SeekBar class is a subclass of ProgressBar , which contains a getProgress() method. Calling PRICEbar. getProgress() will return the value you are looking for.


1 Answers

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.

like image 51
CommonsWare Avatar answered Sep 28 '22 08:09

CommonsWare