设置自定义值来搜索栏 [英] Set Custom values to seek Bar
本文介绍了设置自定义值来搜索栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过2开始我从基地3和增量寻求巴尔及上限为9如何设置,我需要3,5,7,9,11。我的code是
它不工作,因为我想,请大家帮忙
搜索栏SB1 =(搜索栏)findViewById(R.id.sBtaxitype); sb1.setMax(11);
sb1.setLeft(3);
sb1.incrementProgressBy(2);
sb1.setProgress(0); //它设置为零,因此它会在开始的最左侧边缘
sb1.setOnSeekBarChangeListener(新OnSeekBarChangeListener(){ @覆盖
公共无效onProgressChanged(搜索栏搜索栏,INT进步,布尔FROMUSER){
如果(进度3;){
进度= 3;
进度=进步+ 2;
}其他{
进度=进步+ 2; //增加的最小值(10)
} TextView的文本=(TextView的)findViewById(R.id.tvTaxitype);
text.setText(Integer.toString(进度)); } @覆盖
公共无效onStartTrackingTouch(搜索栏搜索栏){} @覆盖
公共无效onStopTrackingTouch(搜索栏搜索栏){} });
解决方案
setLeft()
是定位。 A 搜索栏
总是以0值开始,上升到最大值(默认为100,通过 SETMAX覆盖()
)。
要得到一个3-11范围内,调用 SETMAX(8)
,再加入3〜的结果getProgress()
当你获取当前值。
I want to start My seek baar from base 3 and increment by 2 and max is 9 how to set , i need 3,5,7,9,11. my code is
it not working as i want , please help
SeekBar sb1 = (SeekBar)findViewById(R.id.sBtaxitype);
sb1.setMax(11);
sb1.setLeft(3);
sb1.incrementProgressBy(2);
sb1.setProgress(0); // Set it to zero so it will start at the left-most edge
sb1.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (progress < 3) {
progress = 3;
progress = progress + 2;
} else {
progress = progress + 2; // Add the minimum value (10)
}
TextView text = (TextView)findViewById(R.id.tvTaxitype);
text.setText(Integer.toString(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
});
解决方案
setLeft()
is for positioning. A SeekBar
always starts with a value of 0 and rises to the maximum (100 by default, overridden via setMax()
).
To get a 3-11 range, call setMax(8)
, then add 3 to the result of getProgress()
when you retrieve the current value.
这篇关于设置自定义值来搜索栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文