I've been on this issue for a few days and I can't find a solution.
I tried it first with a class and also with different methods, but I don't quite understand how it works
My intention is to ask the user to indicate the time to start the countdown
I want to use a TimePickerDialog, but this one that I use in particular, only asks for hours and minutes, which by the way, the hours do not let me put 0, and it does not let me put seconds, only minutes. Well, or I don't know how they would wear.
I wish I could select the hours, minutes and seconds.
Collect the three data in three variables and send them to a TextView
TimePickerDialog method:
private void metodoSolicitarTiempo(){
TimePickerDialog timePickerDialog = new TimePickerDialog(PaginaTemporizador.this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
//horas es el textview donde deseo ver el dato que retorna
//ésto funciona, pero aunque ponga 0 horas, siempre aparece 1
//también desearía ver los segundos
Horas.setText(hourOfDay + ":" + minute);
}
}, horas, minutos, false); //ésta parte no la entiendo. Las variables horas y minutos son de tipo int, pero no entiendo porque las hay que colocar y para qué
timePickerDialog.show();
}
This is the method that starts the Timer:
public void IniciarCuenta(){
//Esta parte la utilizaba antes con otro método que pedía horas, minutos y segundos de forma manual por medio de Edittext, ahora no lo utilizo
//segundos = (Integer.parseInt(Segundos.getText().toString()) + (Integer.parseInt(Minutos.getText().toString()) * 60) + ((Integer.parseInt(Horas.getText().toString()) * 60) * 60));
//Lo que trataría de hacer, sería pasar a segundos las tres variales retornadas por el método anterior
new CountDownTimer(segundos * 1000 + 1000, 1000) {
public void onTick(long millisUntilFinished) {
segundos = (int) (millisUntilFinished / 1000);
//Con éstos cálculos mezclo un poco métodos que fui utilizando
//si ahora me llegaran las variables con cada dato de forma individual, algunos de éstos cálculos estaría de más
int horas = segundos / (60 * 60);
int tempMint = (segundos - (horas * 60 * 60));
int minutos = tempMint / 60;
segundos = tempMint - (minutos * 60);
int tempSeg = ((segundos - (horas * 60 * 60))) - (tempMint - (minutos * 60)) - segundos;
miliSegundos = tempSeg / 60;
//Aqui relleno el cuadro de texto con las variables resultantes de los cáculos nateriores donde se va viendo la cuenta atrás en el reloj
txtCronoT.setText(String.format("%02d", horas)
+ ":" + String.format("%02d", minutos)
+ ":" + String.format("%02d", segundos)
+ ":" + String.format("%02d", miliSegundos));
}
public void onFinish() {
txtCronoT.setText("Finalizado");
}
}.start();
}
It would be possible for you to explain to me how the TimePickerDialog method works, and if there is the possibility of requesting the seconds and setting the hours to 0.
I would also like to see the thousandths of a second on the clock and it would also be possible.
Regards, and thank you very much
Well, more or less, I have solved it.
Here the method that shows the penny back
Method that requests the countdown time
And the getTime class that handles the above method
The xml layout that shows the dialog that requests the time