1

I have some specific requirement. I have A seek bar. Now suppose progress is 0, so as I'll increase the seek bar it must go directly 50, and as I increase the seek bar then it must go to directly 100. It is working properly. But now when I decrease the progress then it must go again 50, and when I decrease again then it must go to 0 again. So last two steps is not happening.

@Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            progress_value.setText(progress + "");
            if (progress > 1 && progress <= 50) {
                seek_bar.setProgress(50);
            }
            //seekBar.setSaveEnabled(true);
            if (progress ==100 ) {
                if(progress <100)
                seek_bar.setProgress(50);
            }

            if (progress > 50 && progress < 100) {
                seek_bar.setProgress(100);
            }
        }
Amit Jayaswal
  • 1,725
  • 2
  • 19
  • 36
  • possible duplicate of [Changing step values in seekbar?](http://stackoverflow.com/questions/7329166/changing-step-values-in-seekbar) – waki Dec 25 '14 at 08:49
  • Why you are not trying to specify progress from xml as: – Shankar Dec 25 '14 at 09:41

1 Answers1

3

Make some changes in logic like,

Boolean flag = true, flag1 = true;
seek_bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

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

            int a = seekBar.getProgress();

            if (flag) {
                if (a <= 50 && a > 1) {
                    seek_bar.setProgress(50);
                    flag = false;
                }
            } else {
                if (a <= 50 && a > 1) {
                    seek_bar.setProgress(00);
                    flag = true;
                }
            }
            if (flag1) {
                if (a >= 50 && a < 100) {
                    seek_bar.setProgress(100);
                    flag1 = false;
                }
            } else {
                if (a >= 50 && a < 100) {
                    seek_bar.setProgress(50);
                    flag1 = true;
                }
            }

        }
Ajit Sharma
  • 411
  • 3
  • 8