I replicate how to show datepicker popup from edittext from a question here(i use the accepted answer):
Datepicker: How to popup datepicker when click on edittext
but when im trying to validate if the EditText is not empty, it didnt work. Here is my attempt:
final Calendar myCalendar= Calendar.getInstance();
EditText tStart;
EditText tEnd;
TextInputLayout desc;
Editable tDesc;
Button btnSubmit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_timeoff);
tStart = (EditText) findViewById(R.id.startDate);
tEnd = (EditText) findViewById(R.id.endDate);
Button btnSubmit = (Button) findViewById(R.id.btnSubmit);
DatePickerDialog.OnDateSetListener dateStart =new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
myCalendar.set(Calendar.YEAR, year);
myCalendar.set(Calendar.MONTH,month);
myCalendar.set(Calendar.DAY_OF_MONTH,day);
startupdateLabel();
}
};
DatePickerDialog.OnDateSetListener dateEnd =new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
myCalendar.set(Calendar.YEAR, year);
myCalendar.set(Calendar.MONTH,month);
myCalendar.set(Calendar.DAY_OF_MONTH,day);
endupdateLabel();
}
};
tStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new DatePickerDialog(TimeoffActivity.this,dateStart,myCalendar.get(Calendar.YEAR),myCalendar.get(Calendar.MONTH),myCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
});
tEnd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new DatePickerDialog(TimeoffActivity.this,dateEnd,myCalendar.get(Calendar.YEAR),myCalendar.get(Calendar.MONTH),myCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
});
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(tStart.toString().isEmpty() || TextUtils.isEmpty(tEnd.toString()) ){
Toast.makeText(TimeoffActivity.this, "Please fill all field before submitting", Toast.LENGTH_LONG).show();
} else{
saveTimeoffRequest();
}
}
});
}
I tried using 2 way but still didnt work:
tStart.toString().isEmpty() || TextUtils.isEmpty(tEnd.toString())
how to validate those 2 date EditText if its not empty?
thanks in advance.