如何设置搜索栏最小值和最大值

时间:2021-12-20 07:43:33

I have a seekbar and trying to set the value from 60 to 180 for one and 40 to 190 for the second one in step of 1.

我有一个搜索栏,试图将值设置为60到180为1,而40到190为第二步为1。

sb1 = (SeekBar) findViewById(R.id.progresss);
        sb1.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {       

            @Override       
            public void onStopTrackingTouch(SeekBar seekBar) {      
                // TODO Auto-generated method stub
                //int inVal = Integer.parseInt(String.valueOf(seekBar.getProgress()));
                //inVal =+ 70;
                //Toast.makeText(getApplicationContext(), String.valueOf(inVal),Toast.LENGTH_LONG).show();
            }       

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

            @Override       
            public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {     
                // TODO Auto-generated method stub
                progress =+ 70;
                Toast.makeText(getApplicationContext(), String.valueOf(progress),Toast.LENGTH_LONG).show();

            }       
        });

is not working. Any idea how to fix it?

不管用。知道怎么解决吗?

12 个解决方案

#1


10  

seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {

                int MIN = 5;
                if (progress < MIN) {

                    value.setText(" Time Interval (" + seektime + " sec)");
                } else {
                    seektime = progress;
                }
                value.setText(" Time Interval (" + seektime + " sec)");

            }
        });

#2


84  

I know the answer is already chosen and i'm kinda late on replying but i wanted to share my answer.

我知道答案已经被选中了,我在回复方面有点迟,但我想分享我的答案。

You cannot set the min value of a SeekBar (always 0) and you cannot set the step value of a SeekBar (always 1).

您不能设置SeekBar的最小值(始终为0),并且您不能设置SeekBar的步长值(始终为1)。

If you want to set the value from 60 to 180 with a step of 1 this is the way to do it :

如果要将步长为1的值设置为60到180,则可以执行以下操作:

int step = 1;
int max = 180;
int min = 60;

// Ex : 
// If you want values from 3 to 5 with a step of 0.1 (3, 3.1, 3.2, ..., 5)
// this means that you have 21 possible values in the seekbar.
// So the range of the seek bar will be [0 ; (5-3)/0.1 = 20].
seekbar.setMax( (max - min) / step );


seekbar.setOnSeekBarChangeListener(
    new OnSeekBarChangeListener()
    {
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {}

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {}

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, 
            boolean fromUser) 
        {
            // Ex :
            // And finally when you want to retrieve the value in the range you
            // wanted in the first place -> [3-5]
            //
            // if progress = 13 -> value = 3 + (13 * 0.1) = 4.3
            double value = min + (progress * step);

        }
    }
);

I put another example within the code so that you understand the math.

我在代码中添加了另一个示例,以便您了解数学。

Hope it help

希望它有所帮助

#3


23  

You can set max value for your seekbar by using this code:

您可以使用以下代码为搜索栏设置最大值:

    sb1.setMax(100);

This will set the max value for your seekbar.

这将设置搜索栏的最大值。

But you cannot set the minimum value but yes you can do some arithmetic to adjust value. Use arithmetic to adjust your application-required value.

但是你不能设置最小值但是你可以做一些算术来调整值。使用算术来调整应用程序所需的值。

For example, suppose you have data values from -50 to 100 you want to display on the SeekBar. Set the SeekBar's maximum to be 150 (100-(-50)), then add 50 to the raw value to get the number you should use when setting the bar position.

例如,假设您希望在SeekBar上显示从-50到100的数据值。将SeekBar的最大值设置为150(100 - ( - 50)),然后将50添加到原始值以获取设置条位置时应使用的数字。

You can get more info via this link.

您可以通过此链接获取更多信息。

#4


7  

The easiest way to set a min and max value to a seekbar for me: if you want values min=60 to max=180, this is equal to min=0 max=120. So in your seekbar xml set property:

为我设置最小值和最大值到搜索条的最简单方法:如果你想要值min = 60到max = 180,这等于min = 0 max = 120。所以在你的seekbar xml set属性中:

android:max="120"

min will be always 0.

min将始终为0。

Now you only need to do what your are doing, add the amount to get your translated value in any change, in this case +60.

现在你只需要做你正在做的事情,添加金额以获得任何变化中的翻译价值,在这种情况下为+60。

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            int translatedProgress = progress + 60;
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

Be careful with the seekbar property android:progress, if you change the range you must recalculate your initial progress. If you want 50%, max/2, in my example 120/2 = 60;

注意seekbar属性android:progress,如果你改变了范围,你必须重新计算你的初始进度。如果你想要50%,max / 2,在我的例子中120/2 = 60;

#5


4  

Seek Bar has methods for setting max values but not for setting min value here i write a code for setting minimum seek bar value when we add this code then your seek bar values not less then mim value try this its work fine for me

Seek Bar有设置最大值的方法但不是设置最小值这里我写了一个代码来设置最小搜索条值当我们添加这个代码然后你的搜索栏值不小于mim值试试这个对我来说工作正常

/* This methods call after seek bar value change */

/ *此方法在搜索栏值更改后调用* /

            public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            /* Check the current seekbar value is greather than min value*/
            if (progress < MIN_VALUE) {
                /* if seek bar value is lesser than min value then set min value to seek bar */
                seekBar.setProgress(MIN_VALUE);
            }

        }

#6


1  

Another solution to handle this case is creating a customized Seekbar, to get ride of converting the real value and SeekBar progress every time:

处理这种情况的另一个解决方案是创建一个定制的Seekbar,以便每次都能转换真正的价值和SeekBar进度:

import android.content.Context
import android.util.AttributeSet
import android.widget.SeekBar

//
// Require SeekBar with range [Min, Max] and INCREMENT value,
// However, Android Seekbar starts from 0 and increment is 1 by default, Android supports min attr on API 26,
// To make a increment & range Seekbar, we can do the following conversion:
//
//     seekbar.setMax((Max - Min) / Increment)
//     seekbar.setProgress((actualValue - Min) / Increment)
//     seekbar.getProgress = Min + (progress * Increment)
//
// The RangeSeekBar is responsible for handling all these logic inside the class.

data class Range(val min: Int, val max: Int, private val defaultIncrement: Int) {
    val increment = if ((max - min) < defaultIncrement) 1 else defaultIncrement
}


internal fun Range.toSeekbarMaximum(): Int = (max - min) / increment


class RangeSeekBar: SeekBar, SeekBar.OnSeekBarChangeListener {

    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)

    var range: Range = Range(0, 100, 1)
        set(value) {
            field = value
            max = value.toSeekbarMaximum()
        }

    var value: Int = 0
        get() = range.min + progress * range.increment
        set(value) {
            progress = (value - range.min) / range.increment
            field = value
        }

    var onSeekBarChangeListenerDelegate: OnSeekBarChangeListener? = this

    override fun setOnSeekBarChangeListener(l: OnSeekBarChangeListener?) {
        onSeekBarChangeListenerDelegate = l
        super.setOnSeekBarChangeListener(this)
    }

    override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
        onSeekBarChangeListenerDelegate?.onProgressChanged(seekBar, value, fromUser)
    }

    override fun onStartTrackingTouch(seekBar: SeekBar?) {
        onSeekBarChangeListenerDelegate?.onStartTrackingTouch(seekBar)
    }

    override fun onStopTrackingTouch(seekBar: SeekBar?) {
        onSeekBarChangeListenerDelegate?.onStopTrackingTouch(seekBar)
    }
}

Then in your fragment,

然后在你的片段中,

    // init
    range_seekbar.range = Range(10, 110, 10)
    range_seekbar.value = 20

    // observe value changes
    range_seekbar.userChanges().skipInitialValue().subscribe {
        println("current value=$it")
    }

Keywords: Kotlin, range SeekBar, Rx

关键词:Kotlin,范围SeekBar,Rx

#7


0  

Set seekbar max and min value

设置搜索栏最大值和最小值

seekbar have method that setmax(int position) and setProgress(int position)

thanks

#8


0  

Copy this class and use custom Seek Bar :

复制此类并使用自定义搜索栏:

public class MinMaxSeekBar extends SeekBar implements SeekBar.OnSeekBarChangeListener {
private OnMinMaxSeekBarChangeListener onMinMaxSeekBarChangeListener = null;
private int intMaxValue = 100;
private int intPrgress = 0;
private int minPrgress = 0;


public int getIntMaxValue() {
    return intMaxValue;
}

public void setIntMaxValue(int intMaxValue) {
    this.intMaxValue = intMaxValue;
    int middle = getMiddle(intMaxValue, minPrgress);
    super.setMax(middle);
}

public int getIntPrgress() {
    return intPrgress;
}

public void setIntPrgress(int intPrgress) {
    this.intPrgress = intPrgress;
}

public int getMinPrgress() {
    return minPrgress;
}

public void setMinPrgress(int minPrgress) {
    this.minPrgress = minPrgress;
    int middle = getMiddle(intMaxValue, minPrgress);
    super.setMax(middle);
}

private int getMiddle(int floatMaxValue, int minPrgress) {
    int v = floatMaxValue - minPrgress;
    return v;
}

public MinMaxSeekBar(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.setOnSeekBarChangeListener(this);
}

public MinMaxSeekBar(Context context) {
    super(context);
    this.setOnSeekBarChangeListener(this);
}

@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
    intPrgress = minPrgress + i;
    onMinMaxSeekBarChangeListener.onMinMaxSeekProgressChanged(seekBar, intPrgress, b);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
    onMinMaxSeekBarChangeListener.onStartTrackingTouch(seekBar);

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
    onMinMaxSeekBarChangeListener.onStopTrackingTouch(seekBar);
}

public static interface OnMinMaxSeekBarChangeListener {
    public void onMinMaxSeekProgressChanged(SeekBar seekBar, int i, boolean b);

    public void onStartTrackingTouch(SeekBar seekBar);

    public void onStopTrackingTouch(SeekBar seekBar);
}

public void setOnIntegerSeekBarChangeListener(OnMinMaxSeekBarChangeListener floatListener) {
    this.onMinMaxSeekBarChangeListener = floatListener;
}
}

This class contin method public void setMin(int minPrgress) for setting minimum value of Seek Bar This class contin method public void setMax(int maxPrgress) for setting maximum value of Seek Bar

此类Contin方法public void setMin(int minPrgress)用于设置Seek Bar的最小值此类continue方法public void setMax(int maxPrgress)用于设置Seek Bar的最大值

#9


0  

See my answer here

在这里看到我的答案

I used only listener for SeekBar and it works fine.

我只使用SeekBar的监听器,它工作正常。

#10


0  

Min-value will always start at zero and its nothing you can do about it. But you can change its value when user start scrolling it around.

最小值总是从零开始,你无能为力。但是,当用户开始滚动它时,您可以更改其值。

Here I set the max-value as 64. This calculations are simple: I want the user to pick a time from 15min to 16 hours, and he picks one of every 15min to 16 hours, clear? I know, very simple :)

在这里,我将最大值设置为64.这个计算很简单:我希望用户从15分钟到16个小时选择一个时间,并且他选择每15分钟到16个小时中的一个,清楚吗?我知道,非常简单:)

    SeekBar seekBar = (SeekBar) dialog.findViewById(R.id.seekBar);
    seekBar.setMax(64);

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        float b;

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            float des = (float) progress / 4;
            b = des;
            hours.setText(des + " hours");
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {


        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            hoursSelected = b;
        }
    });

#11


0  

    private static final int MIN_METERS = 100;
    private static final int JUMP_BY = 50;

    metersText.setText(meters+"");
    metersBar.setProgress((meters-MIN_METERS));
    metersBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }
        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
            progress = progress + MIN_METERS;
            progress = progress / JUMP_BY;
            progress = progress * JUMP_BY;
            metersText.setText((progress)+"");
        }
    });
}

#12


-2  

There is no option to set a min or max value in seekbar , so you can use a formula here to scale your value.

没有选项可以在搜索栏中设置最小值或最大值,因此您可以在此处使用公式来缩放您的值。

Desired_value = ( progress * ( Max_value - Min_value) / 100 ) + Min_value

I have tested this formula in many examples. In your example, if the progressBar is the middle(i.e. progress = 50 ) and your Min_val and Max_val are 60 and 180 respectively, then this formula will give you the Desired_value '120'.

我在很多例子中测试了这个公式。在你的例子中,如果progressBar是中间的(即progress = 50),你的Min_val和Max_val分别是60和180,那么这个公式将给你Desired_value'120'。

#1


10  

seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {

                int MIN = 5;
                if (progress < MIN) {

                    value.setText(" Time Interval (" + seektime + " sec)");
                } else {
                    seektime = progress;
                }
                value.setText(" Time Interval (" + seektime + " sec)");

            }
        });

#2


84  

I know the answer is already chosen and i'm kinda late on replying but i wanted to share my answer.

我知道答案已经被选中了,我在回复方面有点迟,但我想分享我的答案。

You cannot set the min value of a SeekBar (always 0) and you cannot set the step value of a SeekBar (always 1).

您不能设置SeekBar的最小值(始终为0),并且您不能设置SeekBar的步长值(始终为1)。

If you want to set the value from 60 to 180 with a step of 1 this is the way to do it :

如果要将步长为1的值设置为60到180,则可以执行以下操作:

int step = 1;
int max = 180;
int min = 60;

// Ex : 
// If you want values from 3 to 5 with a step of 0.1 (3, 3.1, 3.2, ..., 5)
// this means that you have 21 possible values in the seekbar.
// So the range of the seek bar will be [0 ; (5-3)/0.1 = 20].
seekbar.setMax( (max - min) / step );


seekbar.setOnSeekBarChangeListener(
    new OnSeekBarChangeListener()
    {
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {}

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {}

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, 
            boolean fromUser) 
        {
            // Ex :
            // And finally when you want to retrieve the value in the range you
            // wanted in the first place -> [3-5]
            //
            // if progress = 13 -> value = 3 + (13 * 0.1) = 4.3
            double value = min + (progress * step);

        }
    }
);

I put another example within the code so that you understand the math.

我在代码中添加了另一个示例,以便您了解数学。

Hope it help

希望它有所帮助

#3


23  

You can set max value for your seekbar by using this code:

您可以使用以下代码为搜索栏设置最大值:

    sb1.setMax(100);

This will set the max value for your seekbar.

这将设置搜索栏的最大值。

But you cannot set the minimum value but yes you can do some arithmetic to adjust value. Use arithmetic to adjust your application-required value.

但是你不能设置最小值但是你可以做一些算术来调整值。使用算术来调整应用程序所需的值。

For example, suppose you have data values from -50 to 100 you want to display on the SeekBar. Set the SeekBar's maximum to be 150 (100-(-50)), then add 50 to the raw value to get the number you should use when setting the bar position.

例如,假设您希望在SeekBar上显示从-50到100的数据值。将SeekBar的最大值设置为150(100 - ( - 50)),然后将50添加到原始值以获取设置条位置时应使用的数字。

You can get more info via this link.

您可以通过此链接获取更多信息。

#4


7  

The easiest way to set a min and max value to a seekbar for me: if you want values min=60 to max=180, this is equal to min=0 max=120. So in your seekbar xml set property:

为我设置最小值和最大值到搜索条的最简单方法:如果你想要值min = 60到max = 180,这等于min = 0 max = 120。所以在你的seekbar xml set属性中:

android:max="120"

min will be always 0.

min将始终为0。

Now you only need to do what your are doing, add the amount to get your translated value in any change, in this case +60.

现在你只需要做你正在做的事情,添加金额以获得任何变化中的翻译价值,在这种情况下为+60。

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            int translatedProgress = progress + 60;
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

Be careful with the seekbar property android:progress, if you change the range you must recalculate your initial progress. If you want 50%, max/2, in my example 120/2 = 60;

注意seekbar属性android:progress,如果你改变了范围,你必须重新计算你的初始进度。如果你想要50%,max / 2,在我的例子中120/2 = 60;

#5


4  

Seek Bar has methods for setting max values but not for setting min value here i write a code for setting minimum seek bar value when we add this code then your seek bar values not less then mim value try this its work fine for me

Seek Bar有设置最大值的方法但不是设置最小值这里我写了一个代码来设置最小搜索条值当我们添加这个代码然后你的搜索栏值不小于mim值试试这个对我来说工作正常

/* This methods call after seek bar value change */

/ *此方法在搜索栏值更改后调用* /

            public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            /* Check the current seekbar value is greather than min value*/
            if (progress < MIN_VALUE) {
                /* if seek bar value is lesser than min value then set min value to seek bar */
                seekBar.setProgress(MIN_VALUE);
            }

        }

#6


1  

Another solution to handle this case is creating a customized Seekbar, to get ride of converting the real value and SeekBar progress every time:

处理这种情况的另一个解决方案是创建一个定制的Seekbar,以便每次都能转换真正的价值和SeekBar进度:

import android.content.Context
import android.util.AttributeSet
import android.widget.SeekBar

//
// Require SeekBar with range [Min, Max] and INCREMENT value,
// However, Android Seekbar starts from 0 and increment is 1 by default, Android supports min attr on API 26,
// To make a increment & range Seekbar, we can do the following conversion:
//
//     seekbar.setMax((Max - Min) / Increment)
//     seekbar.setProgress((actualValue - Min) / Increment)
//     seekbar.getProgress = Min + (progress * Increment)
//
// The RangeSeekBar is responsible for handling all these logic inside the class.

data class Range(val min: Int, val max: Int, private val defaultIncrement: Int) {
    val increment = if ((max - min) < defaultIncrement) 1 else defaultIncrement
}


internal fun Range.toSeekbarMaximum(): Int = (max - min) / increment


class RangeSeekBar: SeekBar, SeekBar.OnSeekBarChangeListener {

    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)

    var range: Range = Range(0, 100, 1)
        set(value) {
            field = value
            max = value.toSeekbarMaximum()
        }

    var value: Int = 0
        get() = range.min + progress * range.increment
        set(value) {
            progress = (value - range.min) / range.increment
            field = value
        }

    var onSeekBarChangeListenerDelegate: OnSeekBarChangeListener? = this

    override fun setOnSeekBarChangeListener(l: OnSeekBarChangeListener?) {
        onSeekBarChangeListenerDelegate = l
        super.setOnSeekBarChangeListener(this)
    }

    override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
        onSeekBarChangeListenerDelegate?.onProgressChanged(seekBar, value, fromUser)
    }

    override fun onStartTrackingTouch(seekBar: SeekBar?) {
        onSeekBarChangeListenerDelegate?.onStartTrackingTouch(seekBar)
    }

    override fun onStopTrackingTouch(seekBar: SeekBar?) {
        onSeekBarChangeListenerDelegate?.onStopTrackingTouch(seekBar)
    }
}

Then in your fragment,

然后在你的片段中,

    // init
    range_seekbar.range = Range(10, 110, 10)
    range_seekbar.value = 20

    // observe value changes
    range_seekbar.userChanges().skipInitialValue().subscribe {
        println("current value=$it")
    }

Keywords: Kotlin, range SeekBar, Rx

关键词:Kotlin,范围SeekBar,Rx

#7


0  

Set seekbar max and min value

设置搜索栏最大值和最小值

seekbar have method that setmax(int position) and setProgress(int position)

thanks

#8


0  

Copy this class and use custom Seek Bar :

复制此类并使用自定义搜索栏:

public class MinMaxSeekBar extends SeekBar implements SeekBar.OnSeekBarChangeListener {
private OnMinMaxSeekBarChangeListener onMinMaxSeekBarChangeListener = null;
private int intMaxValue = 100;
private int intPrgress = 0;
private int minPrgress = 0;


public int getIntMaxValue() {
    return intMaxValue;
}

public void setIntMaxValue(int intMaxValue) {
    this.intMaxValue = intMaxValue;
    int middle = getMiddle(intMaxValue, minPrgress);
    super.setMax(middle);
}

public int getIntPrgress() {
    return intPrgress;
}

public void setIntPrgress(int intPrgress) {
    this.intPrgress = intPrgress;
}

public int getMinPrgress() {
    return minPrgress;
}

public void setMinPrgress(int minPrgress) {
    this.minPrgress = minPrgress;
    int middle = getMiddle(intMaxValue, minPrgress);
    super.setMax(middle);
}

private int getMiddle(int floatMaxValue, int minPrgress) {
    int v = floatMaxValue - minPrgress;
    return v;
}

public MinMaxSeekBar(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.setOnSeekBarChangeListener(this);
}

public MinMaxSeekBar(Context context) {
    super(context);
    this.setOnSeekBarChangeListener(this);
}

@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
    intPrgress = minPrgress + i;
    onMinMaxSeekBarChangeListener.onMinMaxSeekProgressChanged(seekBar, intPrgress, b);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
    onMinMaxSeekBarChangeListener.onStartTrackingTouch(seekBar);

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
    onMinMaxSeekBarChangeListener.onStopTrackingTouch(seekBar);
}

public static interface OnMinMaxSeekBarChangeListener {
    public void onMinMaxSeekProgressChanged(SeekBar seekBar, int i, boolean b);

    public void onStartTrackingTouch(SeekBar seekBar);

    public void onStopTrackingTouch(SeekBar seekBar);
}

public void setOnIntegerSeekBarChangeListener(OnMinMaxSeekBarChangeListener floatListener) {
    this.onMinMaxSeekBarChangeListener = floatListener;
}
}

This class contin method public void setMin(int minPrgress) for setting minimum value of Seek Bar This class contin method public void setMax(int maxPrgress) for setting maximum value of Seek Bar

此类Contin方法public void setMin(int minPrgress)用于设置Seek Bar的最小值此类continue方法public void setMax(int maxPrgress)用于设置Seek Bar的最大值

#9


0  

See my answer here

在这里看到我的答案

I used only listener for SeekBar and it works fine.

我只使用SeekBar的监听器,它工作正常。

#10


0  

Min-value will always start at zero and its nothing you can do about it. But you can change its value when user start scrolling it around.

最小值总是从零开始,你无能为力。但是,当用户开始滚动它时,您可以更改其值。

Here I set the max-value as 64. This calculations are simple: I want the user to pick a time from 15min to 16 hours, and he picks one of every 15min to 16 hours, clear? I know, very simple :)

在这里,我将最大值设置为64.这个计算很简单:我希望用户从15分钟到16个小时选择一个时间,并且他选择每15分钟到16个小时中的一个,清楚吗?我知道,非常简单:)

    SeekBar seekBar = (SeekBar) dialog.findViewById(R.id.seekBar);
    seekBar.setMax(64);

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        float b;

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            float des = (float) progress / 4;
            b = des;
            hours.setText(des + " hours");
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {


        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            hoursSelected = b;
        }
    });

#11


0  

    private static final int MIN_METERS = 100;
    private static final int JUMP_BY = 50;

    metersText.setText(meters+"");
    metersBar.setProgress((meters-MIN_METERS));
    metersBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }
        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
            progress = progress + MIN_METERS;
            progress = progress / JUMP_BY;
            progress = progress * JUMP_BY;
            metersText.setText((progress)+"");
        }
    });
}

#12


-2  

There is no option to set a min or max value in seekbar , so you can use a formula here to scale your value.

没有选项可以在搜索栏中设置最小值或最大值,因此您可以在此处使用公式来缩放您的值。

Desired_value = ( progress * ( Max_value - Min_value) / 100 ) + Min_value

I have tested this formula in many examples. In your example, if the progressBar is the middle(i.e. progress = 50 ) and your Min_val and Max_val are 60 and 180 respectively, then this formula will give you the Desired_value '120'.

我在很多例子中测试了这个公式。在你的例子中,如果progressBar是中间的(即progress = 50),你的Min_val和Max_val分别是60和180,那么这个公式将给你Desired_value'120'。