0
在這裏,我想過濾Sqlite數據庫,但這個查詢不working.It什麼也沒有顯示。請幫我找出我做錯了什麼? 謝謝!Sqlite查詢(如)不工作不顯示任何東西
public ArrayList<Listcollection> listafterfilter(String s) {
SQLiteDatabase db = this.getReadableDatabase();
ArrayList<Listcollection> results = new ArrayList<Listcollection>();
Cursor crs = null;
while (crs.moveToNext()) {
if(s == null || s.length() ==0){
crs = db.query(CONTACTS_TABLE_NAME, new String[]{C_NAME, C_PHONE , C_TYPE ,C_ADDRESS ,C_DATE,C_PNAME,C_CDATE , C_MNO ,C_DNAME ,C_DPHONE ,
C_TSCHARGE ,C_DAMOUNT ,C_FANDSOL, C_TRNO, C_TCRAMOUNT }, null, null, null,null, null);
Listcollection item = new Listcollection();
item.setId(crs.getInt(crs.getColumnIndex(CONTACTS_COLUMN_ID)));
item.setName(crs.getString(crs.getColumnIndex(C_NAME)));
item.setCdate(crs.getString(crs.getColumnIndex(C_CDATE)));
item.setType(crs.getString(crs.getColumnIndex(C_TYPE)));
results.add(item);
}
else {
crs = db.query(true,CONTACTS_TABLE_NAME, new String[]{C_NAME, C_PHONE , C_TYPE ,C_ADDRESS ,C_DATE,C_PNAME,C_CDATE , C_MNO ,C_DNAME ,C_DPHONE ,
C_TSCHARGE ,C_DAMOUNT ,C_FANDSOL, C_TRNO, C_TCRAMOUNT }, " like '%"+s+"%'",null, null,null, null, null);
Listcollection item = new Listcollection();
item.setId(crs.getInt(crs.getColumnIndex(CONTACTS_COLUMN_ID)));
item.setName(crs.getString(crs.getColumnIndex(C_NAME)));
item.setCdate(crs.getString(crs.getColumnIndex(C_CDATE)));
item.setType(crs.getString(crs.getColumnIndex(C_TYPE)));
results.add(item);
}
}
db.close();
return results;
}