qiujuer/Genius-Android

Seekbar with variable Max

Closed this issue · 13 comments

In my app the seekbar's Max is variable. For example: The current max is 4, and after pressing a button it shall be 5. I tried invalidate() but that didnt work. How can I do that?

Thank you feedback. I will check it.

In my test:

        SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar);
        seekBar.setMax(3);
        seekBar.setMin(1);
        // we try change progress to 0 value
        seekBar.setProgress(0);
        // the progress < min value, so progress auto change to 1 value

        findViewById(R.id.opt).setOnClickListener(new View.OnClickListener() {
            int optCount = 0;

            @Override
            public void onClick(View v) {
                SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar);
                Log.e(MainActivity.this.getClass().getName(),
                        String.format("Before: progress:%s max:%s min:%s", seekBar.getProgress(), seekBar.getMax(), seekBar.getMin()));

                int progress = seekBar.getProgress();
                Log.e(MainActivity.this.getClass().getName(),
                        String.format("Running: try change progress:%s to %s, optCount:%s", progress, ++progress, ++optCount));

                seekBar.setProgress(progress);

                Log.e(MainActivity.this.getClass().getName(),
                        String.format("After: progress:%s max:%s min:%s", seekBar.getProgress(), seekBar.getMax(), seekBar.getMin()));

                // if onclick count > 10
                // we will change the SeekBar max value
                if (optCount == 5) {
                    Log.e(MainActivity.this.getClass().getName(), "Change SeekBar max value to 10.");
                    seekBar.setMax(10);
                    // in this, the SeekBar not refresh progress bar
                    // ....

                    // if you need refresh the widget, you can call
                    seekBar.setProgress(seekBar.getProgress());
                    // or wait me update the SeekBar widget, I fixed quickly
                }
            }
        });

This is bug, I will fix it.

When will there be an update?

Now, you can set compile 'net.qiujuer.genius:ui:1.5.1' to use new version.

Thanks a lot!!!

How can I refresh the view the best way?

In ui:1.5.1 , the view will auto refresh the draw on call setMax() or setMin().
If you only call invalidate() , the view will refresh draw; but the draw parameters not correct.

The view have some logical operations on call setMax() or setMin().

It doesnt work for me. I think it has something to do with genius:gAllowTrackClickToDrag="false".

Here is my code:

 <net.qiujuer.genius.ui.widget.SeekBar
        android:id="@+id/seekBarSatz"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/custom_margin_left_and_right"
        android:layout_marginRight="@dimen/custom_margin_left_and_right"
        android:layout_marginEnd="@dimen/custom_margin_left_and_right"
        android:layout_marginStart="@dimen/custom_margin_left_and_right"
        genius:gAllowTrackClickToDrag="false"
        genius:gIndicator="auto"
        genius:gIndicatorBackgroundColor="@color/primary_dark"
        genius:gIndicatorSeparation="30dp"
        genius:gIndicatorTextAppearance="@style/Genius.Widget.BalloonMarker.TextAppearance"
        genius:gRippleColor="@color/primary_light"
        genius:gScrubberColor="@color/primary_light"
        genius:gScrubberStroke="4dp"
        genius:gThumbColor="@color/primary_dark"
        genius:gThumbSize="6dp"
        genius:gTickSize="5dp"
        genius:gTouchSize="12dp"
        genius:gTrackColor="@color/grey_light"
        genius:gTrackStroke="2dp" />
 seekBarSatz = (SeekBar) findViewById(R.id.seekBarSatz);
        seekBarSatz.setMin(1);
        if(parents.get(0).getChildItemList() == null){
           seekBarSatz.setMax(1);
        }else{
            seekBarSatz.setMax(parents.get(0).getChildItemList().size());
        }

void next(View v){ //This is called by a button
if(child != null){
            seekBarSatz.setMax(parent.getChildItemList().size());
        }else{
            seekBarSatz.setMax(1);
        }}

Oh, ok I know. I will test it. Thanks.

Now you can try to use compile 'net.qiujuer.genius:ui:1.5.2' version.

Now it works. Thx a lot!

You’re welcome!