문제

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()
도움이 되었습니까?

해결책

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
    }

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top