为什么我不能在androidstudio中将这个值从这个方法传递到另一个方法?

3ks5zfa0  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(182)

这个方法是一个计数器,if语句有一个值我想传递给另一个方法。该值称为stagetime

private void startTimer() {
        Log.println(Log.ASSERT, "CHECK","Entered startTimer() method");
        millisInFuture = mTimeLeftInMillis;
        mCountDownTimer = new CountDownTimer(mTimeLeftInMillis, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                mTimeLeftInMillis = millisUntilFinished;
                updateCountDownText();
                final long millisPassed = millisInFuture - mTimeLeftInMillis;
                progress = (int) (millisPassed * 100 / millisInFuture);
                pb.setProgress(progress);
                pb2.setProgress(0);
                pb3.setProgress(0);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //Key: 60 sec
                if (millisInFuture == 480000) {
                    if (millisPassed <= 60000 || (millisPassed > 180000 && millisPassed <= 240000) || (millisPassed > 300000 && millisPassed <= 360000 || (millisPassed > 420000 && millisPassed <= 480000))) {
                        Animation animation = AnimationUtils.loadAnimation(tool1mode1.this, R.anim.fade_in);
                        stepupimage.setAnimation(animation);
                        stage_timer2.setVisibility(View.INVISIBLE);
                        stage_timer.setVisibility(View.VISIBLE);
                        pb3.setProgress(0);
                        stageTime = 60000;
                        Log.println( Log.VERBOSE,"CHECK","StageTime= "+stageTime);
                    } else if ((millisPassed > 60000 && millisPassed <= 180000)) {
                        Animation animation = AnimationUtils.loadAnimation(tool1mode1.this, R.anim.fade_in);
                        stepdownimage.setAnimation(animation);
                        stage_timer.setVisibility(View.INVISIBLE);
                        stage_timer2.setVisibility(View.VISIBLE);
                        pb2.setProgress(0);
                        stageTime = 120000;
//                        stageDown((int) timeleft[5]);
                        Log.println( Log.VERBOSE,"CHECK","StageTime= "+stageTime);
                    } else if ((millisPassed > 240000 && millisPassed <= 300000) || (millisPassed > 360000 && millisPassed <= 420000)){
                        Animation animation = AnimationUtils.loadAnimation(tool1mode1.this, R.anim.fade_in);
                        stepdownimage.setAnimation(animation);
                        stage_timer.setVisibility(View.INVISIBLE);
                        stage_timer2.setVisibility(View.VISIBLE);
                        pb2.setProgress(0);
//                        stageDown((int) timeleft[3]);
                        stageTime = 60000;
                    }

                }

上面这是我倒计时计时器的一部分。
现在我想把stagetime从上面的方法传递到这个方法:

private void stageUp(int value)
{
    mTimeLeftInMillis2 = value ;
    Log.println(Log.VERBOSE, "Check", "stage_time = "+mTimeLeftInMillis2);
    millisInFuture2 = mTimeLeftInMillis2;
   CountDownTimer cdt = new CountDownTimer(mTimeLeftInMillis2, 1000) {
       @Override
       public void onTick(long millisUntilFinished) {
           Log.println(Log.ASSERT, "CHECK2", "stageup entered");
               mTimeLeftInMillis2 = millisUntilFinished;
               updateStageUpCount();
               long timestamp = millisInFuture2 - mTimeLeftInMillis2;
               progress2 = (int) (timestamp*100 /millisInFuture2);
               pb2.setProgress(progress2);

       }

       @Override
       public void onFinish() {

       }
   }.start();

}

这是另一个倒计时计时器,但我将传递的值将决定它将运行多长时间。
现在到了采取行动的时候,第二个方法就永远不会被调用:

newbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startTimer();
            if(stageTime != -1){
                Log.println(Log.ASSERT, "CHECK","Entered stageUp method");
                stageUp(stageTime);
            }

        }
    });

但是,当我手动为stageup方法添加一个值时,它就工作了,你知道如何解决这个问题吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题