I know how to set error on EditText like this:
serverIp.setError("Server IP Is Required");
serverIp.requestFocus();
return;
But in SearchView there is no option to set Error.
Is there any way to get the result?
I know how to set error on EditText like this:
serverIp.setError("Server IP Is Required");
serverIp.requestFocus();
return;
But in SearchView there is no option to set Error.
Is there any way to get the result?
But in
SearchViewthere is no option to set Error.
Indeed. There is no public method (I couldn't find any at least) related to setError() in SearchView since it extends from LinearLayoutCompat and not the EditText to use setError().
Instead, you can use an EditText inside a CardView to handle the setError().
Also, check this out: https://stackoverflow.com/a/47573025/4409113
private fun setErrorOnSearchView(searchView: SearchView, errorMessage: String) {
val id = searchView.context
.resources
.getIdentifier("android:id/search_src_text", null, null)
val editText = searchView.find<EditText>(id)
editText.error = errorMessage
}
You might be able to declare-bypass the SearchView as an EditText to use setError().