-1
I have some Edittext that must be filled. The button that checks if it is filled is an imagebutton in actionbar. I tried to do it in a way but it didn’t work.
the mistake is cnpj.setError(resources.getString(R.string.login_cnpj_required));
xml:
<string name="login_cnpj_required">Campo CNPJ obrigatório!</string>
code:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (cnpj.getText().toString().trim().equals("")) {
cnpj.setError(resources.getString(R.string.login_cnpj_required));
} else if (cnpj.getText().length() < 14) {
cnpj.setError(resources.getString(R.string.login_cnpj_invalid));
}
if (id == R.id.action_pedido) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
What do you mean "it didn’t work"? And where is the statement of
resources
?– Pablo Almeida
i got it, I did it through Boolean Boolean ok = true;
– Carlos Alberto