如何在asyncTask
中使用Cursor
來顯示listView
,因爲我的抓取數據非常龐大(元數據),我應該使用asyncTask。我需要鏈接教程使用Cursor
asyncTask
。如何在asyncTask中使用Cursor獲取大量數據?
我有波紋管的代碼。
我Struct_Search.class
:
public class Struct_Search {
public int MetaData;
public String Value;
public String Name;
public int Number;
}
在我MainActivity.class
:
try {
cursor = sql.rawQuery(
"SELECT MetaDataID,Data,CategoryID,ParentID FROM BOOK WHERE DATA LIKE '"
+ "%" + editable + "%'", null);
array = new ArrayList<String>();
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
Struct_Search note = new Struct_Search();
note.MetaData = cursor.getInt(cursor.getColumnIndex("MetaDataID"));
note.Value = cursor.getString(cursor.getColumnIndex("DATA"));
note.Number = 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();
}
請解釋您的意思是「巨大的」。 – Squonk 2014-12-03 13:44:10
@Squonk。元數據。 – 2014-12-03 13:45:21
你是什麼意思?只需在任務內執行查詢。 – TheRedFox 2014-12-03 13:47:02