Search code examples
androidseekbarandroid-progressbar

Seekbar error in loading the progress on start of the activity


On the start of the activity I have set the progress to 8 ;
so the thumb is on 8 but the background is not on 8 , After changing the seekbar it working fine but on start of the activity it's not...

unable to load image

Thanks in advance...

Code is:-

public static int time=8;

oncreate(){
SeekBar sb=(SeekBar)findViewById(R.id.SB);
TextView tv=(TextView)findViewById(R.id.tv);
sb.setMax(20);
sb.setProgress(time);
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            // TODO Auto-generated method stub
            time=progress;
            tv.setText(time+"");
        }
    });
}

Solution

  • Try to set the max value first. Then try to set the progress.