I am using timepicker to my app,now i am able to set time from timepicker and send it to next activity,now in next activity i am using countdown timer,now in my countdown timer i want to set that time and start timer,following is my code of timepicker and countdowntimer
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String timeofevent = edttmofevent.getText().toString();
Intent intent = new Intent(AddNewEvent.this, EventDetails.class);
intent.putExtra("times",timeofevent);
startActivity(intent);
}
});
private TimePickerDialog.OnTimeSetListener timePickerListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
int hour;
//String am_pm;
if (hourOfDay > 12) {
hour = hourOfDay - 12;
// am_pm = "PM";
} else {
hour = hourOfDay;
//am_pm = "AM";
}
edttmofevent.setText(hour + " : " + minute + " ");
}
};
Countdowntimer
Intent intent=getIntent();
tim=intent.getStringExtra("times");
timerValue.setText(tim);
// final CounterClass timer = new CounterClass(Integer.parseInt(timerValue.getText().toString()), 1000);
playbc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startTime = SystemClock.uptimeMillis();
customHandler.postDelayed(updateTimerThread, 0);
// timer.start();
}
});
pausebc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
timeSwapBuff += timeInMilliseconds;
customHandler.removeCallbacks(updateTimerThread);
// timer.cancel();
}
});
}
private Runnable updateTimerThread = new Runnable() {
public void run() {
timeInMilliseconds = SystemClock.uptimeMillis() - startTime;
updatedTime = timeSwapBuff + timeInMilliseconds;
int secs = (int) (updatedTime / 1000);
int mins = secs / 60;
int hours = mins/60;
secs = secs % 60;
int milliseconds = (int) (updatedTime % 1000);
timerValue.setText(""+ hours +":" + mins + ":"
+ String.format("%02d", secs) + ":"
+ String.format("%03d", milliseconds));
customHandler.postDelayed(this, 0);
}
};
Here hour1 and min1 are default selected time of dialog..