android 异步处理 后台更新

protected void insertData(String name, float price) {
ContentValues values = new ContentValues();
values.put("name", name);
values.put("price", price);
db.insert(BookSQLiteHelper.getTableName(), "name", values);
// cursor.requery();
new RefreshList().execute();//重新更新列表
}

private class RefreshList extends AsyncTask<Void, Void, Cursor> {
protected Cursor doInBackground(Void... params) {
Cursor newCursor = db.rawQuery("SELECT _id,name,price FROM " + BookSQLiteHelper.getTableName()
+ " ORDER BY _id ASC", null);
return newCursor;
}

protected void onPostExecute(Cursor newCursor) {//替换cursor
adapter.changeCursor(newCursor);
cursor.close();
cursor = newCursor;
}
}

你可能感兴趣的:(android)