0

I am trying to search multiple field from search view, but unable to get value.However, i search only one field, then i got the search, but during multiple, i got error.

search field: name, age, country
search text: john, 25, brazil

condition: field can be any order, like country, age Or age, name, age Or name, country.

In User model class, I have name, age and country field.

public class User{
  String name;
  int age;
  String country;
//getters
} 

Here is the code below, works for only one field(name). How to do multiple field.

public boolean onQueryTextChange(String query) {
        query = query.toLowerCase().trim();

       // String [] searchSplit= query.split("\\s");


        final List<User> filteredList = new ArrayList<>();

        for (int i = 0; i < userList.size(); i++) {

            final String textName = userList.get(i).getName().toString().toLowerCase();
            if (textName.contains(query)) {

                filteredList.add(userList.get(i));
            }
        }

Thanks in advance.

JavaRocks
  • 31
  • 3
  • you could use pattern matching using regular expressions to test the input for containing the respective values – Androbin Mar 01 '17 at 17:07
  • Can u check this link, its related to collection mostly and u query says search http://stackoverflow.com/questions/122105/what-is-the-best-way-to-filter-a-java-collection – silentsudo Mar 01 '17 at 18:12

0 Answers0