How can an error message be set for the Spinner in Android?

There are a few solutions in this thread Creating a setError() for the Spinner:

The EdmundYeung99‘s one works for me, either you are using your own adapter or not.
Just put the following code in your validate function:

TextView errorText = (TextView)mySpinner.getSelectedView();
errorText.setError("");
errorText.setTextColor(Color.RED);//just to highlight that this is an error
errorText.setText("my actual error text");//changes the selected item text to this

But, make sure you have at least one value in the Spinner adapter when you are doing your verification. If not, like an empty adapter waiting to be populate, make your adapter get an empty String:

ArrayAdapter<String> adapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, new String[]{""});
mySpinner.setAdapter(adapter);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)