Thursday 10 November 2016

Custom Digital Clock in Android

digitalClockTv = (TextView) findViewById(R.id.digitalClockTv);
countDownTimer = new CountDownTimer(1000000000, 1000) {

    public void onTick(long millisUntilFinished) {
        String hour, minit, sec;
        Calendar c = Calendar.getInstance();
        hour = String.valueOf(c.get(Calendar.HOUR));
        minit = String.valueOf(c.get(Calendar.MINUTE));
        sec = String.valueOf(c.get(Calendar.SECOND));
        int a = c.get(Calendar.AM_PM);
        if (hour.length() == 1) {
            hour = getString(R.string.zero) + hour;
        }
        if (minit.length() == 1) {
            minit = getString(R.string.zero) + minit;
        }
        if (sec.length() == 1) {
            sec = getString(R.string.zero) + sec;
        }
        if (a == Calendar.AM) {
            digitalClockTv.setText(hour + getString(R.string.colon) + minit + getString(R.string.colon) + sec + getString(R.string.am));
        } else {
            digitalClockTv.setText(hour + getString(R.string.colon) + minit + getString(R.string.colon) + sec + getString(R.string.pm));
        }
    }

    public void onFinish() {
    }
};
countDownTimer.start();


Thank You

No comments:

Post a Comment

Send Whatsapp Message via PHP Code

  How to Send and Receive Messages in WhatsApp using PHP In this tutorial you will see How to Send and Receive Messages in WhatsApp using PH...