Code example for SeekBar

Methods: getMaxsetIndeterminatesetProgresssetOnSeekBarChangeListener

0
  public static void bindSliderToVariable(Activity a, int sliderId, int textId, int progress) {
    bindSliderToVariable(a, sliderId, textId, progress, 0);
  } 
  public static void bindSliderToVariable(Activity a, int sliderId, int textId, int progress, final int startAt) {
    SeekBar slider = (SeekBar) a.findViewById(sliderId);
    slider.setIndeterminate(false);
    slider.setProgress(progress - startAt);
    final int max = slider.getMax();
 
    final TextView value = (TextView) a.findViewById(textId);
    value.setText(""+progress);
    slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
      @Override 
      public void onProgressChanged(SeekBar seekBar, int change, boolean fromUser) {
        int scaled = (int) ((max-startAt)/(float)max * change + startAt);
        value.setText(""+scaled);
      } 
      @Override 
      public void onStartTrackingTouch(SeekBar seekBar) {}
      @Override 
      public void onStopTrackingTouch(SeekBar seekBar) {}