Question

I am wondering about how to search in J2ME. I have been searching in the internet, so many result show to me, and I see in Java2s.com I got a result use RecordFilter and matches method for search in record store.

But my problem is, when I need to pass 2 or more parameters into it. How can result matches with these parameter?

And how to sort descending or ascending like bubble sort?

Was it helpful?

Solution

Concatenate your searches into a single String variable. Separate each of them with ; for example. In the code of the matches method explode the String to get each search criteria. To make the filter in effect create an instance of SearchFilter and call the matches method with the concantenated String as its param. For the sort implement the RecordComparator interface ; implement the compare method to build your sort criteria. Make a google search about j2me+recordcomparator to see examples about how to make sorts.


EDIT :

In the code of the matches method explode the String param obtained from the byte[] param. Treat each String exploded to make the criteria. As I understand you want to pass two string as a search criteria when you wrote :

SearchFilter search = new SearchFilter(txtSearch.getString(), strType);

So in the constructor there should be two params !!!

When you want to make the matching then call

if searchFilter.matches((search1+";"+sType).getBytes())

Then explode the candidate param into two String when you code the matches method.

OTHER TIPS

When I save my Data in RMS I save it as a String[] like I want to save Name, Age,Salary,EmpID for each employee I save it create an array and convert it to bytes and save it in RMS. When i retrieve it i do the reverse process. Now if i want to get employee with names starting with A and with salary 10000 i use the following filter

class UtilFilter implements RecordFilter{    
    public UtilFilter(String str_searchText,String str_searchText1)
    {
            this.str_searchText = str_searchText.toLowerCase();
            this.str_searchText1 = str_searchText1.toLowerCase();
    }
    public boolean matches(byte[] bt_byteData)
    {
      String str_str = "";
      String str_str1 = "";
      //here goes code how u get back ur String[] from RMS say u get it in Data
      str_str = Data[0].trim();
      str_str1 = gd_cd.Data[2].trim();

      if(str_searchText != null && str_searchText1 != null && str_str.equals(str_searchText) && str_str1.equals(str_searchText1 ))
        {
              return true;
        }
        else
        {
              return false;
        }
    }
}

This way i can filter any no of parameters.Hope tht helps! :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top