In this exercise, I have to start with one hour of entry (example: 20:30), after that, I have to add the minutes to get the time of departure.
But I have two details which I do not know what they are, the first one indicates an error of "Wrong 2nd argument type. Found: 'long', required: 'int" and the second "Can not resolve method' makeText" What should they do?
package com.example.yasna.myapp_ejerciciohoras;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;
public class MainActivity extends AppCompatActivity {
private EditText edtH1;
private EditText edtM1;
private EditText edtM2;
private EditText edtH2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtH1=(EditText) findViewById(R.id.edtHora);
edtM1=(EditText) findViewById(R.id.edtMin1);
edtM2=(EditText) findViewById(R.id.edtMin2);
edtH2=(EditText) findViewById(R.id.edtHora2);
}
public void calcularHora(View view){
String Hora =edtH1.getText().toString() ; // sin espacio
SimpleDateFormat formato = new SimpleDateFormat("hh:mm");
Date horas = null;
try {
horas = formato.parse(Hora);
} catch (ParseException e) {
e.printStackTrace();
}
String horasformato = formato.format(horas);
/************/
Calendar HoraFinal=Calendar.getInstance();
HoraFinal.setTime(horas);
/***********/
int min= Integer.parseInt(edtM1.getText().toString())+Integer.parseInt(edtM2.getText().toString());
String formato2 = "%02d:%02d" ;
long horasReales = TimeUnit.MINUTES.toHours(min);
long minutosReales = TimeUnit.MINUTES.toMinutes(min) - TimeUnit.HOURS.toMinutes(TimeUnit.MINUTES.toHours(min));
HoraFinal.add(Calendar.HOUR, horasReales);
HoraFinal.add(Calendar.MINUTE, minutosReales);
Toast.makeText(this, HoraFinal.getTime(),Toast.LENGTH_SHORT).show();
Toast.makeText(this, String.format(formato2, horasReales, minutosReales),Toast.LENGTH_SHORT).show();
//aqui
Toast.makeText(this,horasformato,Toast.LENGTH_SHORT).show();
}
}