Android 使用editText和SimpleCorsorAdapter筛选listview
我正在尝试筛选listView中的项目,但它不起作用。我的代码似乎没有响应editText中输入的文本 这是我的SearchActivity类(MainActivity) 这是我的getDirectoryListAndroid 使用editText和SimpleCorsorAdapter筛选listview,android,listview,filter,simplecursoradapter,Android,Listview,Filter,Simplecursoradapter,我正在尝试筛选listView中的项目,但它不起作用。我的代码似乎没有响应editText中输入的文本 这是我的SearchActivity类(MainActivity) 这是我的getDirectoryList public Cursor getDirectoryList (CharSequence constraint) { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.se
public Cursor getDirectoryList (CharSequence constraint) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
queryBuilder.setTables(DB_NAME);
String[] columns = new String[]{KEY_ID, KEY_CONTENT, KEY_DESCRIPTION, KEY_NETWORKING, KEY_HARDWARE, KEY_SOFTWARE, KEY_INTERNET, KEY_TECHNOLOGY};
if (constraint == null || constraint.length () == 0) {
// Return the full list
Cursor cursor = myDataBase.query("MY_TABLE",
columns, null, null, null, null, null);
return cursor;
} else {
String value = constraint.toString()+"%";
Cursor cursor2 = myDataBase.query("MY_TABLE", columns, "KEY_CONTENT like ?", new String[]{value}, null, null, null);
return cursor2;
}
}
}
public Cursor getDirectoryList (CharSequence constraint) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
queryBuilder.setTables(DB_NAME);
String[] columns = new String[]{KEY_ID, KEY_CONTENT, KEY_DESCRIPTION, KEY_NETWORKING, KEY_HARDWARE, KEY_SOFTWARE, KEY_INTERNET, KEY_TECHNOLOGY};
if (constraint == null || constraint.length () == 0) {
// Return the full list
Cursor cursor = myDataBase.query("MY_TABLE",
columns, null, null, null, null, null);
return cursor;
} else {
String value = constraint.toString()+"%";
Cursor cursor2 = myDataBase.query("MY_TABLE", columns, "KEY_CONTENT like ?", new String[]{value}, null, null, null);
return cursor2;
}
}
}