我有Cursor
Select from sqlite
,query
我做了substring
但我可以substring
使用它{&#t}} 39; t告诉我任何错误,但显示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;
答案 0 :(得分:1)
如果您想在字符索引后获取第一个100个字符,并将note.Value设置为它,请将您的子字符串更改为
// substring(int beginIndex, int endIndex)
Result.substring(A, A + 100);
在java中,substring的第二个参数是endIndex,而不是Length。