java Listview搜索不会在退格时刷新
我将搜索过滤器设置为:
SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText){
if (TextUtils.isEmpty(newText)){
searchView.clearFocus();
}
else {
CursorAdapter filterAdapter = (CursorAdapter) Cur;
filterAdapter.getFilter().filter(newText.toString());
}
return true;
}
@Override
public boolean onQueryTextSubmit(String query) {
return true;
}
};
然后:
Cur.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
return dbHelper.getDirectoryList(constraint,stat);
}
});
在我的DBAdapter中:
public Cursor getDirectoryList(CharSequence constraint,String stat) {
open();
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
queryBuilder.setTables(DBAdapter.DATABASE_TABLE1);
String asColumnsToReturn[] = { DBAdapter.DATABASE_TABLE1 + "."
+ DBAdapter.id + "," + DBAdapter.DATABASE_TABLE1 + "."
+ DBAdapter.notificationfor + "," + DBAdapter.DATABASE_TABLE1 + "."
+ DBAdapter.datetonotify + "," + DBAdapter.DATABASE_TABLE1 + "."
+ DBAdapter.isextraordinary + "," + DBAdapter.DATABASE_TABLE1 + "."
+ DBAdapter.notificationdata + "," + DBAdapter.DATABASE_TABLE1 + "."
+ DBAdapter.primaryid + "," + DBAdapter.DATABASE_TABLE1 + "."
+ DBAdapter.type_notifications + "," + DBAdapter.DATABASE_TABLE1 + "."
+ DBAdapter.radio_type_notfi + "," + DBAdapter.DATABASE_TABLE1 + "."
+ DBAdapter.friend_name_not + "," + DBAdapter.DATABASE_TABLE1 + "."
+ DBAdapter.notif_image_Uri + "," + DBAdapter.DATABASE_TABLE1 + "."
+ DBAdapter.notifDob + "," + DBAdapter.DATABASE_TABLE1 + "."
+ DBAdapter.notificationdatefor };
System.out.println(constraint);
if (constraint == null || constraint.length() == 0) {
String query;
System.out.println("Executed"+stat);
if(stat.equalsIgnoreCase("Off")){
query ="SELECT * FROM (SELECT * FROM Notifications WHERE TypeNotification <> 'Event' AND RadioType <> '3'"+" AND DateToNotify < '"+getCurrentDatePlusOne().toString()+"'"+" UNION SELECT * FROM NotificationsCron WHERE TypeNotification <> 'Event' AND RadioType <> '3' ) T ORDER BY SUBSTR(DATE('NOW'), 0)>SUBSTR(DateToNotify, 0), SUBSTR(DateToNotify, 0)";
}else{
query ="SELECT * FROM (SELECT * FROM Notifications WHERE DateToNotify < '"+getCurrentDatePlusOne().toString()+"' UNION SELECT * FROM NotificationsCron) T ORDER BY SUBSTR(DATE('NOW'), 0)>SUBSTR(DateToNotify, 0), SUBSTR(DateToNotify, 0)";
}
return mDb.rawQuery(query, null);
} else {
String value = "%" + constraint.toString() + "%";
// if(stat.equalsIgnoreCase("Off")){
// return mDb.query(DATABASE_TABLE1,asColumnsToReturn,"(NotificationDateFor like ? OR FriendsName like ?)" +" AND TypeNotification <> 'Event' AND RadioType <> '3' ORDER BY DateToNotify ASC",new String[] { value, value}, null,null, null);
// }else{
return mDb.query(DATABASE_TABLE1,asColumnsToReturn,"(NotificationDateFor like ? OR FriendsName like ?)" +" ORDER BY DateToNotify ASC",new String[] { value, value}, null,null, null);
// }
}
}
一切正常,但当我使用backspace时,列表不会恢复到原始光标。如果我输入Jim,它会显示所有名字为Jim的人,但当我使用退格时,过滤器会停留在以J开头的名字上。我在这里遗漏了什么
共 (0) 个答案