How to set first Seekbar process value is to assign initial value of second Seekbar in Android?

你说的曾经没有我的故事 提交于 2019-12-02 06:10:50

问题


I have two seekbars. I want to set first Seekbar process value is to assign initial value of second Seekbar. My Exact requirement is, I want cover 0 to 100 with three seekbar.Ex : If FirstSeekBar cover 1 to 30 the Second SeekBar automatically starts 30 to 100. if I set process value 60 in second seekbar the Third Seekbar automatically starts 60 to 100. Please help me to solve this problem.

activity.xml

<SeekBar
    android:id="@+id/firstSeekBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"/>
<SeekBar
    android:id="@+id/secondSeekBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp" />
<SeekBar
    android:id="@+id/thirdSeekBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp" />

SeekBarActivity.java

firstSeekBar.setOnSeekBarChangeListener(
            new SeekBar.OnSeekBarChangeListener() {
                int firstPgrValue;
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    firstPgrValue = progress;
                    secondSeekBar.setEnabled(true);
                    txtFirstSeek.setText("First (" + progress + " / " + firstSeekBar.getMax() + ")");
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                    shortMessage(MainActivity.this, "Progress Start");
                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    if (firstPgrValue == 0) {
                        secondSeekBar.setEnabled(false);
                        redSeekBar.setEnabled(false);
                    }
                    txtFirstSeek.setText("First (" + firstPgrValue + " / " + firstSeekBar.getMax() + ")");
                    shortMessage(MainActivity.this, "Progress Stopped");
                }
            }
    );

    secondSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        int secondPgrValue;
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            secondPgrValue = progress;
            thirdSeekBar.setEnabled(true);
            txtSecondSeek.setText("Second (" + progress + " / " + secondSeekBar.getMax() + ")");
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            shortMessage(MainActivity.this, "Progress Start");
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        if (secondPgrValue == 0) {
           thirdSeekBar.setEnabled(false);
        }
            txtSecondSeek.setText("Second (" + secondPgrValue + " / " + secondSeekBar.getMax() + ")");
            shortMessage(MainActivity.this, "Progress Stopped");
        }
    });
thirdSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        int thirdPsrValue;
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            thirdPsrValue = progress;
            txtRedSeek.setText("Third (" + progress + " / " + redSeekBar.getMax() + ")");
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            shortMessage(MainActivity.this, "Progress Start");
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            txtThirdSeek.setText("Third (" + thirdPsrValue + " / " + thirdSeekBar.getMax() + ")");
            shortMessage(MainActivity.this, "Progress Stopped");
        }
    });

回答1:


Unfortunately vanilla SeekBar does not have a default min field. I store this value in parallel with untidy and inconvenient int fields. You could extend the class, or do as I do, but it seems to me you are describing a common situation, the functionality for which is already provided by many RangeBar implementations.

My Exact requirement is, I want cover 0 to 100 with three seekbar.Ex : If FirstSeekBar cover 1 to 30 the Second SeekBar automatically starts 30 to 100. if I set process value 60 in second seekbar the Third Seekbar automatically starts 60 to 100.

https://github.com/yahoo/android-range-seek-bar has just two thumbs and should be ideal. Others provide unlimited thumbs.



来源:https://stackoverflow.com/questions/32756044/how-to-set-first-seekbar-process-value-is-to-assign-initial-value-of-second-seek

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!