0
在下面的代碼中,過濾不區分大小寫。我想,當我在我的應用程序寫ABC就不會也顯示出ABC,ABC,ABC,ABC和ABC濾波將是大小寫敏感的,例如:我希望下面的過濾區分大小寫,即當我編寫ABC時,它不會顯示aBc等。
private ListView lv;
ArrayAdapter<String> adapter;
EditText inputSearch;
ArrayList<HashMap<String, String>> productList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String products[] = {"ABC", "abc", "aBc", "Abc", "abC"
};
lv = (ListView) findViewById(R.id.list_view);
inputSearch = (EditText) findViewById(R.id.inputSearch);
adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_name, products);
lv.setAdapter(adapter);
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
MainActivity.this.adapter.getFilter().filter(cs);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
@Override
public void afterTextChanged(Editable arg0) {
}
});
}
}
,你需要像一些自定義適配器:'類適配器extends' [MatchableArrayAdapter(https://gist.github.com/pskink/2dd4d17a93caf02ff696533e82f952b0)' {... '並覆蓋它的'matches'方法 –
pskink