Search code examples
blackberryjava-meseekbar

How to create a seekbar in blackberry?


I need to create a seek bar in my blackberry app like in android. all i need to do with it is to just slide it to the right or left to increase and decrease. does seekbar exist in blackberry or is it called as a slider in blackberry?


Solution

  • Create a SliderScreen:

    public class SliderScreen extends MainScreen implements FieldChangeListener
    {
        private SliderField slider;
        private HorizontalFieldManager hm;
    
        public SliderField(){
            slider = new SliderField(
                Bitmap.getBitmapResource("slider2_thumb_normal.png"),
                Bitmap.getBitmapResource("slider2_progress_normal.png"),
                Bitmap.getBitmapResource("slider2_base_normal.png"),
                Bitmap.getBitmapResource("slider2_thumb_focused.png"),
                Bitmap.getBitmapResource("slider2_progress_focused.png"),
                Bitmap.getBitmapResource("slider2_base_focused.png"), 
                8, 4, 8, 8, FOCUSABLE);
    
            slider.setChangeListener(this);
            hm = new HorizontalFieldManager();
            hm.add(slider);
            setStatus(hm);
        }
    
        public void fieldChanged(Field field, int context) {
            try {
                if (field == slider) {
                    int value = slider.getValue();
                }
            } catch (IllegalStateException e) {
                e.printStackTrace();
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
        }    
    

    and Finally get the SliderField Class and SliderImages From this BlackBerry Documents

    you can get the seekbar images from BlackBerry samples