我有一个带有两个 TexView
的自定义 ListView
,我用下面的代码用一个 SimpleAdapter 填充它
adapter = new SimpleAdapter(this, list,
R.layout.activity_lista_vehiculo,
new String[] { "value1","value2" },
new int[] {R.id.line_a, R.id.line_b});
setListAdapter( adapter );
我如何从 EditText
或 SearchView
中添加过滤器?
最佳答案
SimpleAdapter
有一个内置的 SimpleFilter
,它使用前缀过滤 ListView 适配器
的内容。如果这是你想要的,你可以使用下面的代码来完成过滤工作:
yourEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
yourSimpleAdapter.getFilter().filter(cs);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
@Override
public void afterTextChanged(Editable arg0) {
}
});
关于java - 使用两个 TextView 将过滤器添加到 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28145241/