0
votes

I'm new at learning Android, and working on a simple timer program. As of now, I have the code set up to create the timer from a passed in int. The design has a start button that will start the timer and refresh the TextView every second with the new time.

Right now, I'm working on pausing and restarting the timer. My idea is canceling the CountDownTimer when the user clicks pause and getting the new value for a new CountDownTimer from the TextView that is displaying the time when the user paused (Display as 00:00).

How do I parse the string from the TextView, getting the separate numbers for minutes and seconds?

2
If you have access to the timer, why would you want to retrieve the information from the TextView?Josh M

2 Answers

2
votes

Ok Good you can separate string and get as a minute and second Use This

String minute=textView1.getText().split(":")[0];
    String second=textView1.getText().split(":")[1];

You can convert String in Int using

int min=Integer.parseInt(minute);

or use

int min=Integer.ValueOf(minute);
0
votes

Try this:

Timer t=new Timer();

        t.schedule(new TimerTask() {

            @Override
            public void run() {
                final Date d = new Date();
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        textView.setText(d.getMinutes() +":" + d.getSeconds());
                    }
                });
            }
        }, 0,1000);