如何将CountdownTimer嵌套在另一个CountdownTimer中?

时间:2018-04-01 16:12:09

标签: java android

所以我有两个Countdowntimers,我希望一个嵌套在另一个的onFinish中。我不想使用runnable因为我觉得它对我的应用程序不利,因为它很难取消。这在执行中看起来相当简单,但我一直都会遇到错误。

final CountDownTimer TheTimer;
    final CountDownTimer FinalTimer;

    TheTimer = new CountDownTimer((cdTime), 1000) {

        public void onTick(long millisUntilFinished) {

            button.setText(String.valueOf(millisUntilFinished));
            if(millisUntilFinished <= 10000){
                button.setVisibility(View.GONE);
            }

        }

        public void onFinish() {


            FinalTimer = new CountDownTimer(10000, 1000) {
                @Override
                public void onTick(long l) {

                }

                @Override
                public void onFinish() {

                }
            }.start();

        }
    }.start();

错误:无法为最终变量赋值。

然而,Ide是告诉我最后的那个

Visual Aid

如果我让第二个计时器不是最终的,我会得到什么 What I get if I make the second timer not final

1 个答案:

答案 0 :(得分:1)

试试这段代码:

$ ./xidel -s "so_49592301.xml" \
> -e '"road,way_id,seq_num,node_ref_id"' \
> -e '//way[tag[@k="name"]]/(
>       nd/join(
>         (
>           ../tag[@k="name"]/@v,
>           ../@id,
>           position(),
>           @ref
>         ),
>         ","
>       )
>     )'
road,way_id,seq_num,node_ref_id
Engineer Road,10459706,1,89705976
Engineer Road,10459706,2,89798118
Engineer Road,10459706,3,89798120
Engineer Road,10459706,4,89798122
Engineer Road,10459706,5,89798124
Engineer Road,10459706,6,89798126
Engineer Road,10459706,7,89798128
Engineer Road,10459706,8,89798130
5th Cutoff Street,10461171,1,89804458
5th Cutoff Street,10461171,2,89804460
5th Cutoff Street,10461171,3,89804463
5th Cutoff Street,10461171,4,89804464
5th Cutoff Street,10461171,5,89804466
5th Cutoff Street,10461171,6,89804468

尝试尽早设置最终变量,以确保它们正确启动。对于未来问题:请尽量保持代码格式良好,并提供有关您所遇问题的足够信息,如错误代码等。