I currently have a countdown timer on my second activity. What I am trying to do is set the textView on my main activity to the value of the countdown timer on my secondActivity. Here is my code for the countdown timer.
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// put your logic here to set the time with hourPicked and minPicked variables
timer = new CounterClass((hours * 60 * 1000) + (minutes * 1000), 1000);
String hms = String.format(("%02d:%02d:"), hours, minutes);
textViewTime.setText(hms);
timer.start();
}
});
noPickerHours.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
hours = newVal;
timer = new CounterClass((hours * 60 * 1000), 1000);
String hms = String.format(("%02d:%02d"), hours, minutes);
textViewTime.setText(hms);
}
});
noPickerMinutes.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
minutes = newVal;
timer = new CounterClass((minutes * 1000), 1000);
String hms = String.format(("%02d:%02d"), hours, minutes);
textViewTime.setText(hms);
Bundle timerBundle = new Bundle();
timerBundle.putInt("%02d:%02d", Integer.parseInt(hms));
Intent timerIntent = new Intent();
}
})
public class CounterClass extends CountDownTimer {
/**
* @param millisInFuture The number of millis in the future from the call
* to {@link #start()} until the countdown is done and {@link #onFinish()}
* is called.
* @param countDownInterval The interval along the way to receive
* {@link #onTick(long)} callbacks.
*/
public CounterClass(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
public void onTick(long millisUntilFinished) {
long millis = millisUntilFinished;
String hms = String.format("%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
System.out.println(hms);
textViewTime.setText(hms);
}
@Override
public void onFinish() {
}
}}