Search code examples
searchblackberryfreetext

BlackBerry 5.0 Control for free-text search


I'm developing a BlackBerry 5.0 app.

I have an entity to be displayed on screen in a grid format. Entity: Employee Fields: EmpId(int), FirstName(string), LastName(string), Hobby(string)

Once I display the list of entites (which I know how to do), I also need to provide an option for the user to be able to search for an employee (similar to the contacts list). However, the search should be a free-text search and on any field.

E.g. if I have 3 employees 1|Ian|Botham|Cricket 2|Ravi|Shastri|Cricket 3|Ravi|Bopara|Football

and if the user types Ravi, it should show up emp 2 & 3. If he types Cricket, it should show up 1&2 and so forth.

I have tried using KeywordFilterField. However, I'm able to search only on one field. How can I extend this to search for more fields? Or is there a different way to do this? Are there any out-of-the-box controls available for this kind of functionality?

Thanks in advance


Solution

  • Say you have a class for your entity

    class Entity
    {
     int empId;
     String firstName;
     String lastName;
     String hobby ;
    
    public String getSearchableString()
    
    {
        return firstName+lastName+hobby;
        }
    }
    

    Every time you do a search , check to compare entityObject.getSearchableString().

    by doing it this way, everytime there is a match in either firstName,lastName or hobby, the search will pick up this object.