A better SeekBar for Android

Still working on Part 2 of my Android development retrospective but I thought I would put this out here real quick.

One of the smaller pain points in developing for Android was the SeekBar object. The SeekBar is a UI widget object that is roughly analogous to the UISlider in Cocoa Touch.

The UISlider has settable minimum and maximum values (in float) and the slider’s current value is expressed as a float.

The SeekBar for Android always has a minimum of zero and the maximum can be set but only to an int. The current progress is always expressed as an int.

This kind of sucks so I made a class that extends SeekBar and named it BetterSeekBar. You can set minimum and maximum values as float and get the current value as a float as well. Internally, it sets the max to an int of 10,000 and calculates the current value based on floating point offsets and ratios.

You can get the BetterSeekBar.java class right from here (it’s 2KB.) I hope you find it useful!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: