1

我有一个Cursor那个Select from sqlite,在这个query我做了一个substring但我不能从中使用substring它不会给我任何错误,但会显示我是listView空的。

    try {
        String value = editText.getText().toString();
        cursor = sql.rawQuery(
                "SELECT MetaDataID,Data,CategoryID,ParentID FROM Book WHERE Data LIKE '"
                        + "%" + value + "%'", null);
        if (cursor != null) {
            if (cursor.moveToFirst()) {
                do {
                    Struct_Search note = new Struct_Search();
                    note.MetaData = cursor.getInt(cursor.getColumnIndex("MetaDataID"));
                    Result = cursor.getString(cursor.getColumnIndex("Data"));
                    int A = Result.indexOf(value);
                    String V = Result.substring(A,100);
                    note.Value = V;
                    note.NumberAyeh = cursor.getInt(cursor.getColumnIndex("CategoryID"));
                    ParentID = cursor.getInt(cursor.getColumnIndex("ParentID"));
                    CursorSecond = sql.rawQuery("SELECT name FROM ContentList WHERE id ="+ ParentID, null);
                    if (CursorSecond != null) {
                        do {
                            CursorSecond.moveToFirst();
                            note.NameSureh = CursorSecond.getString(CursorSecond.getColumnIndex("name"));
                            CursorSecond.close();
                        } while (CursorSecond.moveToNext());
                    }
                    notes.add(note);
                } while (cursor.moveToNext());
            }
            adapter.notifyDataSetChanged();
        }
    } catch (Exception e) {
    } finally {
        cursor.close();
    }

注意:这条线不起作用:

                String V = Result.substring(A,100);
                note.Value = V;
4

1 回答 1

1

如果您尝试在字符索引后获取前 100 个字符,并将 note.Value 设置为它,请将您的子字符串更改为

 // substring(int beginIndex, int endIndex)
 Result.substring(A, A + 100);

在java中,substring的第二个参数是endIndex,而不是Length。

于 2014-12-04T09:24:21.390 回答