我想知道如何在 J2ME 中进行搜索。我一直在互联网上搜索,向我展示了很多结果,我在Java2s.comRecordFilter
中看到我得到了在记录存储中搜索的结果使用和匹配方法。
但我的问题是,当我需要向其中传递 2 个或更多参数时。结果如何与这些参数匹配?
以及如何像冒泡排序一样进行降序或升序排序?
将您的搜索连接到单个字符串变量中。;
例如,将它们分开。在matches
方法的代码中分解字符串以获取每个搜索条件。要使过滤器生效,请创建一个 SearchFilter 实例并matches
使用连接的 String 作为其参数调用该方法。对于sort
实现RecordComparator
接口;实现该compare
方法来构建您的排序标准。对 j2me+recordcomparator 进行 google 搜索,以查看有关如何进行排序的示例。
编辑 :
在matches
方法的代码中,爆炸从 byte[] 参数获得的 String 参数。对待每个分解的字符串以制定标准。据我了解,您希望在编写时传递两个字符串作为搜索条件:
SearchFilter search = new SearchFilter(txtSearch.getString(), strType);
所以在构造函数中应该有两个参数!
当您要进行匹配时,请致电
if searchFilter.matches((search1+";"+sType).getBytes())
然后在编写方法candidate
时将参数分解为两个字符串。matches
当我将数据保存在 RMS 中时,我将其保存为字符串 [],就像我想为每个员工保存姓名、年龄、薪水、EmpID 一样,我保存它创建一个数组并将其转换为字节并将其保存在 RMS 中。当我检索它时,我会执行相反的过程。现在,如果我想获得名称以 A 开头且薪水为 10000 的员工,我使用以下过滤器
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;
}
}
}
这样我可以过滤任何参数。希望有帮助!:)