Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在sqlite android中通过搜索词的起始字母获取所有数据?_Java_Android_Sqlite_Cursor_Android Sqlite - Fatal编程技术网

Java 如何在sqlite android中通过搜索词的起始字母获取所有数据?

Java 如何在sqlite android中通过搜索词的起始字母获取所有数据?,java,android,sqlite,cursor,android-sqlite,Java,Android,Sqlite,Cursor,Android Sqlite,我有搜索字符串。例如:如果我键入co,我需要得到键入的c的所有起始字母并显示列表 但它只显示确切的ca列表。如何仅显示输入字符串中字母表的起始字母 在下面的查询中,显示文本是显示给定输入的描述的表 public List<BaseTableOfContents> searchNodesForText(@Nullable String rootHash, @Nulla

我有搜索字符串。例如:如果我键入co,我需要得到键入的c的所有起始字母并显示列表

但它只显示确切的ca列表。如何仅显示输入字符串中字母表的起始字母

在下面的查询中,显示文本是显示给定输入的描述的表

public List<BaseTableOfContents> searchNodesForText(@Nullable String rootHash,
                                                            @Nullable String substring) {
        List<BaseTableOfContentsNode> returnValue = null;
        if (StringUtils.isNotEmpty(substring) && StringUtils.isNotEmpty(rootHash)) {
            String likeQuery = "%" + substring + "%";
            Cursor cursor = mDatabase.query(Tables.TOC_NODES, null,
                                            Columns.TOC_ROOT_NODE_HASH + " = ? AND (" +
                                            Columns.DISPLAY_TEXT + " LIKE ? OR " +
                                            Columns.TOC_IS_TITLE_BREAK + " = 1)",
                                            new String[] { rootHash, likeQuery }, null, null,
                                            Columns.TOC_SORT_ORDER + ORDER_ASCENDING);

            returnValue = getNodesFromCursor(cursor);
            cursor.close();
        }
public List searchNodesForText(@Nullable String rootHash,
@可为空的字符串(子字符串){
List returnValue=null;
if(StringUtils.isNotEmpty(子字符串)和&StringUtils.isNotEmpty(rootHash)){
字符串likeQuery=“%”+子字符串+“%”;
Cursor Cursor=mDatabase.query(Tables.TOC_节点,null,
Columns.TOC_ROOT_NODE_HASH+“=”和(“+
Columns.DISPLAY_TEXT+“LIKE?或”+
Columns.TOC_是_TITLE_BREAK+“=1)”,
新字符串[]{rootHash,likequaly},null,null,
Columns.TOC_SORT_ORDER+ORDER_升序);
returnValue=getNodesFromCursor(光标);
cursor.close();
}
下面是硬编码的。你可以看到硬编码的“compensacion”文本。但是如果我键入compensacion,它应该列出所有以“c”开头的列表

public List searchNodesForText(@Nullable String rootHash,
@可为空的字符串(子字符串){
List returnValue=null;
if(StringUtils.isNotEmpty(子字符串)和&StringUtils.isNotEmpty(rootHash)){
String likeQuery=“%”“+”compensacion“+”%;//这里我硬编码了。只有当我给出确切的术语时,它才会显示,否则它不会显示。
Cursor Cursor=mDatabase.query(Tables.TOC_节点,null,
Columns.TOC_ROOT_NODE_HASH+“=”和(“+
Columns.DISPLAY_TEXT+“LIKE?或”+
Columns.TOC_是_TITLE_BREAK+“=1)”,
新字符串[]{rootHash,likequaly},null,null,
Columns.TOC_SORT_ORDER+ORDER_升序);
returnValue=getNodesFromCursor(光标);
cursor.close();
}
使用此

public List<BaseTableOfContents> searchNodesForText(@Nullable String rootHash,
                                                            @Nullable String substring) {
        List<BaseTableOfContentsNode> returnValue = null;
        if (StringUtils.isNotEmpty(substring) && StringUtils.isNotEmpty(rootHash)) {
            String likeQuery = "%" + substring.indexOf(0) + "%";
            Cursor cursor = mDatabase.query(Tables.TOC_NODES, null,
                                            Columns.TOC_ROOT_NODE_HASH + " = ? AND (" +
                                            Columns.DISPLAY_TEXT + " LIKE ? OR " +
                                            Columns.TOC_IS_TITLE_BREAK + " = 1)",
                                            new String[] { rootHash, likeQuery }, null, null,
                                            Columns.TOC_SORT_ORDER + ORDER_ASCENDING);

            returnValue = getNodesFromCursor(cursor);
            cursor.close();
        }
public List searchNodesForText(@Nullable String rootHash,
@可为空的字符串(子字符串){
List returnValue=null;
if(StringUtils.isNotEmpty(子字符串)和&StringUtils.isNotEmpty(rootHash)){
字符串likeQuery=“%”+子字符串.indexOf(0)+“%”;
Cursor Cursor=mDatabase.query(Tables.TOC_节点,null,
Columns.TOC_ROOT_NODE_HASH+“=”和(“+
Columns.DISPLAY_TEXT+“LIKE?或”+
Columns.TOC_是_TITLE_BREAK+“=1)”,
新字符串[]{rootHash,likequaly},null,null,
Columns.TOC_SORT_ORDER+ORDER_升序);
returnValue=getNodesFromCursor(光标);
cursor.close();
}
substring.indexOf(0)
获取文本的第一个字符并显示 所有以该字母开头的数据


如果我需要前两个字符的意思,我需要使用indexOf(0)和indexOf(1)?在使用indexOf(1)之前,首先检查您的文本必须是2个字符,否则它将给您
超出索引的
异常
public List<BaseTableOfContents> searchNodesForText(@Nullable String rootHash,
                                                            @Nullable String substring) {
        List<BaseTableOfContentsNode> returnValue = null;
        if (StringUtils.isNotEmpty(substring) && StringUtils.isNotEmpty(rootHash)) {
            String likeQuery = "%" + substring.indexOf(0) + "%";
            Cursor cursor = mDatabase.query(Tables.TOC_NODES, null,
                                            Columns.TOC_ROOT_NODE_HASH + " = ? AND (" +
                                            Columns.DISPLAY_TEXT + " LIKE ? OR " +
                                            Columns.TOC_IS_TITLE_BREAK + " = 1)",
                                            new String[] { rootHash, likeQuery }, null, null,
                                            Columns.TOC_SORT_ORDER + ORDER_ASCENDING);

            returnValue = getNodesFromCursor(cursor);
            cursor.close();
        }