-1
I created an NN/NN/NNNN mask in my editText to capture due date, without a calendar, all done in edt. Then I used Simpledateformat to capture the current system date. I made a comparison with the edt mask and the varialvel (current date) of the simpledateformat. But I think the comparison is not working. The created condition does not appear. I type the current date, but there is no "test" (condition I created as a test).
Field mask
final EditText edtDataSelecionada = (EditText) findViewById(R.id.edtDataSelecionada);
//Criando a mascara de campo
SimpleMaskFormatter smf = new SimpleMaskFormatter("NN/NN/NNNN");
MaskTextWatcher mtw = new MaskTextWatcher(edtDataSelecionada, smf);
edtDataSelecionada.addTextChangedListener(mtw);
//fim da mascará
Simpledateformat and condition
item.setDataselecionada(String.valueOf(edtDataSelecionada.getText().toString().trim()));
SimpleDateFormat formataData = new SimpleDateFormat("dd/MM/yyyy");
Date data = new Date();
String dataFormatada = formataData.format(data);
if (edtDataSelecionada.getText().toString() == dataFormatada){
item.setNotificacao("Teste");
}
Another thing, I’d like to make comparisons with the separate dd of the MM.
The method
format
of aSimpleDateFormat
returns aString
. And in Java, strings must be compared withequals
, not with the operator==
. Then just doif (edtDataSelecionada.getText().toString().equals(dataFormatada)) { etc... }
– hkotsubo