我正在處理一個包含查找欄的片段,如果使用了editText元素,則查找欄值會更新。用戶也可以通過在editText中輸入值來更新seekbar(這一切都有效,直到我實現清除先前的值)上一個EditText值按要求清除,但不允許輸入新用戶
seekbar默認爲500(中點),textView顯示500。 seekbar進度更改時,editText中的值與它匹配。 (這種作品)
當用戶通過選擇EditText元素輸入新值時,我希望500(或什麼值)消失爲新的輸入。 (這工作)。
問題是:每當我在軟鍵盤上輸入一個新值並選擇該值時,新值剛剛清除,softkeyboard仍然保持不變,並且進度條或edittext不更新。什麼做錯了?
搜索欄 - 更新的EditText
private int radius = 500;
//START SEEKBAR DISTANCE
distControl=(SeekBar)view.findViewById(R.id.sb_loc_dist_set);
txtInMaxMiles=(EditText)view.findViewById(R.id.txt_max_num_input);
distControl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
{
int progressChange = 0;
@Override
public void onProgressChanged (SeekBar seekBar,int progress, boolean fromUser){
radius = progress;
txtInMaxMiles.setText(String.valueOf(radius));
}
@Override
public void onStartTrackingTouch (SeekBar seekBar){
distControl.setProgress(radius);
}
@Override
public void onStopTrackingTouch (SeekBar seekBar){
txtInMaxMiles.setText(String.valueOf(radius));
}});//END: SEEK BAR DISTANCE
編輯文本 - 更新進度條
txtInMaxMiles.addTextChangedListener(new TextWatcher() {
String txtIn;
@Override //Before screen fully loads
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// txtIn = txtInMaxMiles.getText().toString();
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
txtIn = txtInMaxMiles.getText().toString();
}
@Override
public void afterTextChanged(Editable s) {
txtIn = txtInMaxMiles.getText().toString();
if (txtIn == null || txtIn.trim().equals("")) {
radius = 0;
}
if (radius < 1 || radius > 1000) {
txtInMaxMiles.setError("Please input a number between 0 and 1001");
} else {
txtInMaxMiles.setError(null);
distControl.setProgress(Integer.parseInt(s.toString()));
// txtInMaxMiles.setText(Integer.toString(radius));
}
}
});
Click上的EditText元素
txtInMaxMiles.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtInMaxMiles.setText("");
}
});
return view;
我認爲這是一個quickfix,但即時失蹤,所以任何幫助將不勝感激。