Pregunta

Now i do search in names in list but i want when i enter characters in edit text, it returns names which contain words start with theses characters not contain it in any position

for example : i am searching for these characters (ste), then it returns that result :

1 - Al Bernstein
2 - Ben Stein
3 - Steve Jobs
4 - John Stewart

i don'y want first name because it hasn't word start with these characters but three others are right

this is my code :

auName.toLowerCase().contains(s.toString().toLowerCase()
¿Fue útil?

Solución

1 - Al Bernstein 2 - Ben Stein 3 - Steve Jobs 4 - John Stewart

i don'y want first name because it hasn't word start with these characters but three others are right

From above sample it seems the word you are searching also has one important thing.. its "Ste" i.e "S" is uppercase..

you can simply search so..

auName.contains(s.toString())

where s = "Ste";

or else if you still want to go to search with "ste" then

//check presence of word at start and after apace
    if(auName.toLowerCase().startswith(s.toString().toLowerCase()) || auName.toLowerCase().contains(" " + s.toString().toLowerCase())){
    //your code
    }

Otros consejos

Use String.startsWith(String prefix) to find if a string starts with another string

http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#startsWith(java.lang.String)

Since you want either first name or second name you'll need to split your Strings first and check if either start with your search term.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top