I’m struggling implementing a custom validator in my Android app.
I want to show in a list view some suggestions retrieved from a server (which works correctly) even if the don’t start with the same letters of the text in my AutoCompleteTextView.
So, i.e. if I write “n” i’d like to get the server response, wich is “r”.
So, i tried to implement a validatore setting up the isValid sample which controls if the server response is not empty.
I show my code here:
autoCompleteTextView.setAdapter(adapter);
autoCompleteTextView.setValidator(new Validator());
autoCompleteTextView.performValidation();
and here Validator class:
class Validator implements AutoCompleteTextView.Validator {
public boolean isValid(CharSequence text) {
Log.v("Test", "Checking if valid: ");
int i = 0;
if (!MainActivity.interventos.isEmpty()) {
return true;
}
return false;
}
public CharSequence fixText(CharSequence arg0) {
// TODO Auto-generated method stub
return null;
}
isValid() returns me always False, but it should return me True because MainActivity.interventos is not empty.
Ps: The entire method works good if the server responses with a word which starts with the same letters as in AutocompleteTextView.
Suggestion?
Thanks in advance
I had a similar problem which I worked out using a CustomArrayAdapter with A viewHolder implements a filter to get data from server. So, you can show in AutoComplete list data you need.
And so validator is not useful and you don’t need it.
Enjoy and keep me up!!