【发布时间】:2018-10-06 09:26:34
【问题描述】:
我在我的 android 应用程序中使用 SQLite 数据库。当我进行搜索操作时,我随机发现了这个错误“应用程序没有关闭光标”。这段代码有什么问题吗?这是代码
field.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
@Override
public void onTextChanged(CharSequence s, int arg1, int arg2, int arg3) {
String test = s.toString().trim();
if (test.isEmpty()) {
if (myCursor != null)
myCursor.close();
myCursor = getReceipts1Data(orderTypes);
myAdapter = new CustomCursorAdapter(activity, myCursor, CursorAdapter.NO_SELECTION);
lView.setAdapter(myAdapter);
}
}
});
public Cursor getReceipts1Data(Global.OrderType[] orderTypes)
{
String subquery1 = "SELECT ord_id as _id,ord_total,ord_issync,cust_id,isVoid,ord_type" +
" FROM Orders WHERE ord_type IN (";
String subquery2 = ") AND isOnHold = '0' ORDER BY rowid DESC";
Cursor cursor = DBManager.getDatabase().rawQuery(subquery1 + getOrderTypesAsSQLArray(orderTypes) + subquery2, null);
cursor.moveToFirst();
return cursor;
}
【问题讨论】: