我的问题是,我想搜索“咖喱屋”,让我说插入“咖喱屋”。空间将消失结果。但如果我搜索没有空格的结果,那就完美了。
MainActivity.java
ADAhere = new SimpleAdapter(getActivity(), data, R.layout.mainproductitem, new String[]{"CategoryName"}, new int[]{R.id.mainproductitem});
mainlistproduct.setAdapter(new PrimaryFragment().ADAhere);
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
mainlistproduct.setTextFilterEnabled(true);
mainlistproduct.setFilterText(cs.toString().trim());
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
if(arg0.length()==0){
mainlistproduct.clearTextFilter();
}
}
});
答案 0 :(得分:0)
mainlistproduct.setFilterText(cs.toString().trim());
每次输入内容时,都会在开头和结尾自动修剪空格。
所以..
curr
- > curr
curry
- > curry
curry[space]
- > curry[no_space]
curry h
- > curryh
答案 1 :(得分:0)
修剪搜索字符串,然后从字符串中替换空格,然后搜索字符串。
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
String input = cs.toString().trim();
input = input.replace(" ", "");
mainlistproduct.setFilterText(input);
}
答案 2 :(得分:0)
从onTextChanged()
删除trim()。只需使用mainlistproduct.setFilterText(cs.toString());
答案 3 :(得分:0)
我修改了你的代码,试试这个
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
mainlistproduct.setTextFilterEnabled(true);
mainlistproduct.setFilterText(cs.toString());
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
if(arg0.length()==0){
mainlistproduct.clearTextFilter();
}
}
});