我想做的就是这个!我有一个文本视图,其中包含用户插入的总预算,另一个文本视图包含费用总和。 反正有没有获得seekbar max值来获取textview1值并增加textview2上的总值?
如果我不应该使用搜索栏,请指出我正确的方向!
提前致谢!
答案 0 :(得分:0)
使用SeekBar的Editable to setMax(int)上的Integer.parseInt将EditChangedListener添加到EditText。要设置时间间隔,您需要将用户从第二个EditText获取后的数量四舍五入到最近的间隔值...
EditText etMaxValue, etInterval;
SeekBar seekBar;
int interval = 1;
public IntervalSeekBar() {
//Initialize your EditText and SeekBar objects...
etMaxValue.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable text) {
seekBar.setMax(Integer.parseInt(text.toString()));
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}
});
etInterval.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable text) {
interval = Integer.parseInt(text.toString());
if (interval < 1) { interval = 1; }
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}
});
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar sb, int value, boolean userInitiated) {
value = ((int) Math.round(value/interval)) * interval;
seekBar.setProgress(value);
}
public void onStartTrackingTouch(SeekBar arg0) { }
public void onStopTrackingTouch(SeekBar arg0) {}
});
}