recyclerView中的倒数计时器始终加速

时间:2017-07-19 03:58:14

标签: android timer android-recyclerview seekbar countdowntimer

我在自定义的recyclerView适配器中有一个倒数计时器。计时器运行一个搜索栏,显示一分钟内的进度。 recyclelerView中的所有项目都假设在搜索栏中显示相同的进度 我的问题是,在搜索栏第一次达到最大进度后,倒数计时器似乎总是加速。如何让倒数计时器保持同样的速度?

我的recyclerView适配器中的O​​nCreateViewHolder:

  @Override
public ViewHolder onCreateViewHolder(ViewGroup parent, final int viewType) {

     vi = LayoutInflater.from(parent.getContext()).inflate(R.layout.businesslistitem, parent, false);

    final SeekBar seekbar = (SeekBar) vi.findViewById(R.id.seekBar);

    //Use previous seekbar position
    if (POSITION != 0) {
        seekBar.setProgress(PROFITPOSITION);
    }

    //Disabling touch events
    seekBar.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            return true;
        }
    });

    countDownTimer = new CountDownTimer(60000, 60) {
        @Override
        public void onTick(long l) {
            seekBar.setProgress(profit_bar.getProgress() + 1);
            POSITION = seekBar.getProgress();

            //If the seekBar reaches it's max the CounDownTimer finishes
            if (seekBar.getProgress() == 1000) {
                onFinish();
            }
        }

        @Override
        public void onFinish() {
            seekBar.setProgress(0);
            PROFITPOSITION = 0;
            countDownTimer.cancel();
            start();
        }
    }.start();

    return new ViewHolder(vi);

}

0 个答案:

没有答案