[英]Can't reset a listview after filtering
I currently have a list view that is populated in my 'onCreate' i have an edit text that is filtering by a constraint passed to my 'onTextChanged' method, this is then sent to a 'getChanges' method in my database handler class and using an LIKE statement it is filtered. 我目前有一个列表视图,该列表视图填充在“ onCreate”中,我的编辑文本通过传递给我的“ onTextChanged”方法的约束进行过滤,然后将其发送到数据库处理程序类中的“ getChanges”方法中,并使用一个LIKE语句,将其过滤。 At the moment when I have deleted the string search from my edittext (ie it is blank) I want all of the contants to redisplay.
在我从编辑文本中删除字符串搜索的那一刻(即它为空白)时,我希望所有内容都重新显示。 Currently I cannot get it to do this, the data shown just shows the last filtered data.
目前,我无法执行此操作,显示的数据仅显示最后过滤的数据。
This is my Filter: 这是我的过滤器:
searchName = (EditText) findViewById(R.id.inputName);
searchedListResults.setTextFilterEnabled(true);
searchName.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
cursorAdapter.getFilter().filter(s.toString());
}
});
getCons = new DBHandler(this, null, null);
cursorAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
getCons.open();
return getCons.getChanges(constraint.toString());
}
});
And this is the method in my database handler class, at first I thought it was because I was closing the cursor in my 'IF' but this dosent seem to make a difference. 这是我的数据库处理程序类中的方法,起初我以为是因为我要关闭“ IF”中的游标,但是这似乎有所不同。
public Cursor getChanges(String constraintPassed) {
String [] columns = new String[]{KEY_ROWID, KEY_NAME, KEY_TEL, KEY_EMAIL, KEY_COMMENTS};
Cursor c = null;
if(constraintPassed == "" || constraintPassed.length() == 0)
{
c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, KEY_NAME + " ASC", null);
c.close();
}
else
{
c = ourDatabase.query(DATABASE_TABLE, columns, KEY_NAME + " LIKE'" + constraintPassed + "%'", null, null, null, KEY_NAME + " ASC", null);
}
if( c != null)
{
c.moveToFirst();
return c;
}
return null;
}
}
You should use this after the filtration : 您应该在过滤后使用它:
((EfficientAdapter)listview.getAdapter()).notifyDataSetChanged();
where EfficientAdapter
is your Adapter class. 其中
EfficientAdapter
是您的Adapter类。
Hope this will work for you. 希望这对您有用。
Try replacing the line 尝试更换线
cursorAdapter.getFilter().filter(s.toString());
with 与
yourclassname.this.cursorAdapter.getFilter().filter(s.toString());
in your onTextChanged
method. 在您的
onTextChanged
方法中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.