I am working on a fragment that holds a seek bar, the seek bar value is updated in the editText element if used . User can also update seekbar by typing in the value on the editText.(this all works, until i implemented the clearing of the previous value)
the seekbar is defaulted to 500 (midpoint) and the textView shows 500. As the seekbar progress changes, the value in the editText matches it. (this kind of works)
When the user inputs a new value by selecting the EditText element I wanted the 500 (or what ever value) to disappear for the new input. (this works).
The problem is: every time I enter a new value on the softkeyboard and select the tick,the new value just clears, the softkeyboard still stays up and the progress bar or the edittext is not updated. What have done wrong?
SEEKBAR - Updating 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
Edit Text - updating progress bar
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));
}
}
});
On Click EditText element
txtInMaxMiles.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtInMaxMiles.setText("");
}
});
return view;
I think this is a quickfix, but im just missing something so any help would be appreciated.