1

每次我触摸它时,我都想从我的应用程序中的 seekbar 中获得价值。我在 seekbar 中声明的值将添加到我的 url 但每次我触摸 seekbar 时它都会给我一个循环,并且 url 将循环并加载为数量 seekbar on progressChanged。这是我的代码:

int period = 0;
SeekTime.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub
    }

    @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
        if (SeekTime.getProgress() <= 3){
            SeekTime.setProgress(0);
            period=7;
        }
        if (SeekTime.getProgress() > 3 && SeekTime.getProgress() <= 8) {
            SeekTime.setProgress(5);
            period =30;
        }
        if (SeekTime.getProgress() >8 && SeekTime.getProgress()<=13){
            SeekTime.setProgress(10);
            period = 90;
        }
        if (SeekTime.getProgress() >13 && SeekTime.getProgress()<=18){
            SeekTime.setProgress(15);
            period = 180;
        }
        if (SeekTime.getProgress() >18 && SeekTime.getProgress()<=23){
            SeekTime.setProgress(20);
            period = 270;
        }
        if (SeekTime.getProgress() >23){
            SeekTime.setProgress(25);
            period = 360;
        }
        new LoadData(URL+period).execute();
4

1 回答 1

1

我认为您遇到的问题是因为当您调用 SeekTime.setProgress() 时,进度正在改变 - 它再次调用 onProgressChange()。

您应该做的是检查用户是否已完成进度更改。你有 fromUser 变量,允许你控制它。

int period = 0;
SeekTime.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
    // TODO Auto-generated method stub
}

@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
if(fromUser) {
    if (SeekTime.getProgress() <= 3){
        SeekTime.setProgress(0);
        period=7;
    }
    if (SeekTime.getProgress() > 3 && SeekTime.getProgress() <= 8) {
        SeekTime.setProgress(5);
        period =30;
    }
    if (SeekTime.getProgress() >8 && SeekTime.getProgress()<=13){
        SeekTime.setProgress(10);
        period = 90;
    }
    if (SeekTime.getProgress() >13 && SeekTime.getProgress()<=18){
        SeekTime.setProgress(15);
        period = 180;
    }
    if (SeekTime.getProgress() >18 && SeekTime.getProgress()<=23){
        SeekTime.setProgress(20);
        period = 270;
    }
    if (SeekTime.getProgress() >23){
        SeekTime.setProgress(25);
        period = 360;
    }
    new LoadData(URL+period).execute();
}
}
于 2013-05-27T04:10:42.580 回答