Android AutoCompleteTextView For URL addresses
I have a problem with Android. When you are using AutoCompleteTextView :
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.entry);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.url_addresses);
String[] url_addresses = getResources().getStringArray(R.array.url_addresses);
for (String string : url_addresses) {
adapter.add(string);
}
textView.setAdapter(adapter);
.....
And when you entered the "google" keyword in textbox, auto complete system showing all urls which is start with "google". For example:
- google.com
- google.com.tr
- google.co.uk
But, I want to show urls which is contains "google". For example:
- http://www.google.com/
- https://mail.google.com/
- http://another.google.co开发者_如何学Cm/
I think this problem occurred if item does not contains any space (one word, like url).
It is possible?
Thanks a lot.
That should be simple. Wrap the url string into another class and in toString
return the url with dots replaced with spaces. For example, The url http://mail.google.com
will be returned as http://mail google com
which will be matched easily by the filter. You can replace other characters also similarly before returning the string seperated by spaces. Like //
class urlString {
String url;
public String toString() {
return url.replace('.',' ');// replace dots with space
}
}
IIRC, Write your own adapter instead of using the base ArrayAdapter. See the Filter.performFiltering... Android AutoCompleteTextView with Custom Adapter filtering not working
精彩评论