I am trying to set an error message on spinner when items are not selected. Also I would love focusing to spinner when the error occurs. I tried some codes for it but it doesn't work well. Especially, the code for focusing on spinner.
You can see my codes below.
public boolean controlCheck(){
int selectedItemOfMySpinner=spinner.getSelectedItemPosition();
// String actualPositionOfMySpinner= (String) spinner.getItemAtPosition(selectedItemOfMySpinner);
if(selectedItemOfMySpinner<1){
Toast.makeText(context, "LOKANATA:)", Toast.LENGTH_SHORT).show();
TextView errorText= (TextView) spinner.getSelectedView();
errorText.setError("");
errorText.setTextColor(Color.RED);
errorText.setText("my actual error text");
return false;
}
if(TextUtils.isEmpty(btnDate.getText().toString())){
btnDate.setError("Bu alan boş olamaz");
btnDate.requestFocus();
return false;
}
if(TextUtils.isEmpty(btnTime.getText().toString())){
btnTime.setError("Bu alan boş olamaz");
btnTime.requestFocus();
return false;
}
if(TextUtils.isEmpty(kisisayisi.getText().toString())){
kisisayisi.setError("Bu alan boş olamaz");
kisisayisi.requestFocus();
return false;
}
if(TextUtils.isEmpty(edtTel.getText().toString())){
edtTel.setError("Bu alan boş olamaz");
edtTel.requestFocus();
return false;
}
if(edtTel.getText().toString().length()<18)
{
edtTel.setError("telefon numarasını eksiksiz giriniz");
edtTel.requestFocus();
return false;
}
if(TextUtils.isEmpty(namesurname.getText().toString())){
namesurname.setError("Bu alan boş olamaz");
namesurname.requestFocus();
return false;
}
return true;
}
Any suggestion?