I have some EditText that should be filled out. The button that checks if it is filled is an imagebutton in the actionbar. I tried to do it one way but it did not work.
error 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);
}