你好我在编辑文本中搜索列表项目的文本时遇到问题我在编辑文本中写了一些字母表给了我许多文本组合所以如何只获得匹配的起始文本我的app图像添加在这里检查它和{{ 0}}帮助我
我的代码是
list = (ListView) findViewById(R.id.listview);
for (int i = 0; i < state.length; i++)
{
property p = new property (state[i],
website[i]);
arraylist.add(p);
}
adapter = new ListViewAdapter(this, arraylist);
list.setAdapter(adapter);
editsearch = (EditText) findViewById(R.id.search);
editsearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
String text = editsearch.getText().toString().toLowerCase(Locale.getDefault());
adapter.filter(text);
}
});
}
答案 0 :(得分:1)
将您的功能onTextChanged
更改为:
@Override
public void onTextChanged(CharSequence cs, int start, int before, int count) {
MainActivity.this.adapter.getFilter().filter(cs);
}