Col*_*ter 7 android listview filter
如果事情没有意义,请告诉我.我知道我的问题并不总是准确的.
我有一个listview,我试图按名称过滤.我有一个EditText字段,用户键入该字段以过滤列表视图.覆盖DirectoryListing类中的toString,允许进行正确的比较.
这是问题所在:假设我有以下内容,每个都在listview中各自的行中:"AC,BC,CD,AE".现在在编辑文本字段中,如果输入B,则列表视图显示"AC".A将显示AC,BC.正如您所看到的,它将显示与输入内容匹配的项目数量,但它只显示自上而下的适当数量,而不是正确的项目.知道我做错了什么吗?这是我的代码.
//imports and some variable declaration
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.directory);
final Handler handler = new Handler() {
//fill the listview to start
}
};
listing = new ArrayList<DirectoryListing>();
this.adapter = new DirectoryAdapter(this, R.layout.dir_rows, listing);
setListAdapter(adapter);
ProgressDialog = ProgressDialog.show(DirectoryActivity.this, "Please wait...", "Retrieving data ...", true);
viewOrders = new Runnable() {
//execute filling the original listview
};
TextWatcher filterTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
adapter.getFilter().filter(s);
adapter.notifyDataSetChanged();
}
};
filterText = (EditText) findViewById(R.id.search_box);
filterText.addTextChangedListener(filterTextWatcher);
Thread thread = new Thread(null, viewOrders, "Background");
thread.start();
}
//other code
Run Code Online (Sandbox Code Playgroud)
}
归档时间: |
|
查看次数: |
354 次 |
最近记录: |