Reputation: 3953
I am working on an Android application in which I am using seek bar to show increment of the values. When I am moving the seek bar and stop the movement it gives me any value for example 2.3, which is fine.
However, I want to work the seek bar in this way that when I am moving the seek bar with the movement the numbers should also change. My code is given below:
start=-10; //you need to give starting value of SeekBar
end=10; //you need to give end value of SeekBar
SeekBar seek=(SeekBar) findViewById(R.id.seekBar1);
seek.setProgress(start_position);
seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "discrete = "+String.valueOf(discrete), Toast.LENGTH_SHORT).show();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
// TODO Auto-generated method stub
// To convert it as discrete value
float temp=progress;
float dis=end-start;
discrete=(start+((temp/100)*dis));
}
});
Upvotes: 0
Views: 2731
Reputation: 7974
Check that you are not setting your text or using Toast message in onProgressChanged which gets triggered everytime you move your seekbar so do it on your onProgressChanged
check the following code snippet:-
@Override
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
// TODO Auto-generated method stub
// To convert it as discrete value
float temp=progress;
float dis=end-start;
discrete=(start+((temp/100)*dis));
Log.e("value is -->",String.valueOf(discrete));
}
});
see that your toast works on onStopTrackingTouch which triggers when the movement stops. use above and check your logcat for values and then you may perform your desired function.
Upvotes: 1