我试图改变的进步,搜索栏
基于在的EditText
但对于一些输入的号码原因的EditText
值变为最大,我不能在滑动拇指搜索栏
。
我在找实现:如果输入的值的的EditText
70和190之间的任何地方(包括数量)更改搜索栏到该值。
部分的Java code:
一通网络=(EditText上)findViewById(R.id.etSyst);
etOne.addTextChangedListener(新TextWatcher(){
公共无效afterTextChanged(编辑S){
串filtered_str = s.toString();
如果(的Integer.parseInt(filtered_str)> = 70&安培;&放大器;的Integer.parseInt(filtered_str)< = 190){
sbSyst.setProgress(的Integer.parseInt(filtered_str));
}
}
公共无效beforeTextChanged(CharSequence中,诠释开始,诠释计数,之后INT){}
公共无效onTextChanged(CharSequence中,诠释开始,诠释之前,诠释计数){}
});
的部分XML:
<搜索栏
机器人:ID =@ + ID / syst_bar
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_margin =10dp
机器人:进度=0
机器人:最大=120
机器人:progressDrawable =@可绘制/ progress_bar
机器人:secondaryProgress =0
机器人:拇指=@可绘制/ thumb_state/>
我加70到每一个值,因为搜索栏
0时开始,但我希望它开始在70。
使用上述code后,这是什么样子:
在搜索栏
是最大号和的EditText
是在最大为好。
一通网络=(EditText上)findViewById(R.id.etSyst);
etOne.addTextChangedListener(新TextWatcher(){
公共无效afterTextChanged(编辑S){
INT I =的Integer.parseInt(s.toString());
如果(ⅰ> = 70&安培;&安培; I&其中; = 190){
sbSyst.setProgress(I - 70); //这将确保0-120值搜索栏
}
}
公共无效beforeTextChanged(CharSequence中,诠释开始,诠释计数,之后INT){}
公共无效onTextChanged(CharSequence中,诠释开始,诠释之前,诠释计数){}
});
I am trying to change the progress of a SeekBar
based on the number entered in an EditText
but for some reason the EditText
value goes to the max and I can't slide the thumb in the SeekBar
.
What I am looking to achieve: If the value entered in the EditText
anywhere between 70 and 190 (including both number) change the progress of the SeekBar
to that value.
Partial Java code:
etOne = (EditText) findViewById(R.id.etSyst);
etOne.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
String filtered_str = s.toString();
if (Integer.parseInt(filtered_str) >= 70 && Integer.parseInt(filtered_str) <= 190) {
sbSyst.setProgress(Integer.parseInt(filtered_str));
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
The partial XML:
<SeekBar
android:id="@+id/syst_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:progress="0"
android:max="120"
android:progressDrawable="@drawable/progress_bar"
android:secondaryProgress="0"
android:thumb="@drawable/thumb_state" />
I add 70 to each value, because SeekBar
starts at 0, but I want it to start at 70.
After using the above code, this is what it looks like:
The SeekBar
is at the maximum number and the EditText
is at the maximum as well.
etOne = (EditText) findViewById(R.id.etSyst);
etOne.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
int i = Integer.parseInt(s.toString());
if (i >= 70 && i <= 190) {
sbSyst.setProgress( i - 70); // This ensures 0-120 value for seekbar
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});