I have a TextView
that I fill with DatePickerDialog
and TimePickerDialog
, I also have to default by automatically adding the date and time of the day on which We are, because here is my problem. I have since I need to fill TextView
to move forward, if you leave blank you get a message asking you to fill TextView
but as I said above, by default you add the hour and < em> date therefore it is never empty.
How can I do to recognize my TextView
as empty when the time and date
Or putting it another way, that does not recognize that it is filled with the automatic text
Here my code: (The class is not complete, only what I think it takes to try to solve my problem)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
editTextFecha = (TextView) findViewById(R.id.editTextFecha);
Calendar calendario = Calendar.getInstance();
dia = calendario.get(Calendar.DAY_OF_MONTH);
mes = calendario.get(Calendar.MONTH);
ano = calendario.get(Calendar.YEAR);
hora = calendario.get(Calendar.HOUR_OF_DAY);
minutos = calendario.get(Calendar.MINUTE);
mostrarFecha();
selectorFecha = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
dia = dayOfMonth;
mes = month;
ano = year;
mostrarFecha();
mostrarHora();
}
};
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 0:
return new DatePickerDialog(this, selectorFecha, ano, mes, dia);
}
return null;
}
public void mostrarCalendario(View control) {
showDialog(TIPO_DIALOGO);
}
public void mostrarFecha() {
editTextFecha.setText(dia + "/" + (mes + 1) + "/" + ano + " " + hora + ":" + String.format("%02d", minutos));
}
private void mostrarHora() {
TimePickerDialog timePickerDialog = new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
hora = hourOfDay;
minutos = minute;
mostrarFecha();
}
}, hora, minutos, true);
timePickerDialog.show();
}
// aqui compruebo que los campos estén rellenos, en este caso 'Fecha' es lo que estamos mirando
btnguardar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (verificarCampoNombre() && verificarCampoFecha()
&& verificarCampoZodiaco()) {
if (estadoEditarPersona()) {
editarPersona();
} else {
try {
abc_id = (int)insertarNuevoPersona();
} catch (Exception e) {
e.printStackTrace();
}
}
finish();
} else {
if (editTextNombre.getText().toString().equals("")) {
mensaje.mostrarMensajeCorto(getResources().getString(R.string.intro_nombre));
}
if (editTextFecha.getText().toString().equals("")) {
mensaje.mostrarMensajeCorto(getResources().getString(R.string.intro_fecha));
}
if (editTextZodiaco.getText().toString().equals("")) {
mensaje.mostrarMensajeCorto(getResources().getString(R.string.intro_zodiaco));
}
}
}
});
private boolean verificarCampoFecha() {
if (editTextFecha.getText().toString().equals("")) {
return false;
}
return true;
}
}
}
Is it possible? Or I have to remove the date and time