如何检测搜索栏进度变化是减少还是增加?
How to detect whether a seekbar progress change is decreasing or increasing?
进度变化事件可以在接口OnSeekBarChangeListener()
中通过onProgressChanged
通知。
但是如何知道变化是减少进度还是增加进度?或者是否有类似的接口或方法:
onSeekBarProgressDecreased(....)
或 onSeekBarProgressIncreased(...)
private prevValue;
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
if(progressValue < prevValue){
Toast.makeText(getApplicationContext(), "Progress decreased", Toast.LENGTH_SHORT).show();
}else if(progressValue > prevValue){
Toast.makeText(getApplicationContext(), "Progress increased", Toast.LENGTH_SHORT).show();
}
prevValue = progresValue;
}
....
}
没有可用于进度减少或增加事件的接口。你必须跟踪它。你可以使用这样的东西。
int prevProgress;
mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
@Override
public oid onProgressChanged (SeekBar seekBar, int progress, boolean fromUser){
int diff = progress - prevProgress;
if(diff > 0){
//increase
}
else{
//decrease
}
prevProgress = progress;
}
});
进度变化事件可以在接口OnSeekBarChangeListener()
中通过onProgressChanged
通知。
但是如何知道变化是减少进度还是增加进度?或者是否有类似的接口或方法:
onSeekBarProgressDecreased(....)
或 onSeekBarProgressIncreased(...)
private prevValue;
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
if(progressValue < prevValue){
Toast.makeText(getApplicationContext(), "Progress decreased", Toast.LENGTH_SHORT).show();
}else if(progressValue > prevValue){
Toast.makeText(getApplicationContext(), "Progress increased", Toast.LENGTH_SHORT).show();
}
prevValue = progresValue;
}
....
}
没有可用于进度减少或增加事件的接口。你必须跟踪它。你可以使用这样的东西。
int prevProgress;
mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
@Override
public oid onProgressChanged (SeekBar seekBar, int progress, boolean fromUser){
int diff = progress - prevProgress;
if(diff > 0){
//increase
}
else{
//decrease
}
prevProgress = progress;
}
});