Countdown Timer required on Android

前端 未结 4 1737
粉色の甜心
粉色の甜心 2020-12-06 23:05

Here is the link where i have discussed about a countdown timer of format(mm:ss) in Java:

Java console code for StopWatch/Timer?

Now i want to display (and u

4条回答
  •  离开以前
    2020-12-06 23:13

    To count down

    You'll use a TextField and update its content using CountDownTimer, or check Rahul's answer in this same question.

    To count up

    In your Activity

    import android.widget.Chronometer;
    
    ...
    
    private Chronometer crono;
    
    protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
    
     setContentView(R.layout.screen_crono);    
    
     this.crono = (Chronometer) findViewById(R.id.calling_crono);
    
        startCrono();
    }
    
    public void startCrono() {
     crono.setBase(SystemClock.elapsedRealtime());
     crono.start();
    }
    

    To stop it

    crono.stop();
    

    In the XML Layout screen_crono

    
    

    To set it inside a TextView, I don't think that's possible. Place it to its right or to its left, depending on what you want.

    If this is not what you wanted, I hope it helps someone else.

提交回复
热议问题