Arrayadapter Filter Return Wrong Items
I have problem with filtering array adapter with custom object. I owerride custom object toString() so it returns name- which I want filter. Problem is that it filer correct count
Solution 1:
List<Customer> customers = new List<Customer>();
List<Customer> tempcustomers = new List<Customer>();
customers = repository.getCustomers();
etSearch .addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
System.out.println("onTextChanged Key presed..."+s);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
System.out.println("beforeTextChanged Key presed..."+filterText.getText());
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
System.out.println("afterTextChanged Key presed..."+filterText.getText());
if (!etSearch .getText().toString().equalsIgnoreCase("")){
tempcustomers = new List<Customer>();
String text = etSearch .getText().toString();
for(int i=0 ;i< customers .size();i++){
if(customers .get(i).toUpperCase().toString().contains(text.toUpperCase())){
tempcustomers .add(customers .get(i));
}
}
}
customerAdapter = new CustomerAdapter(this,
R.layout.customers_list_item,tempcustomers );
setListAdapter(customerAdapter);
}else{
customerAdapter = new CustomerAdapter(this,
R.layout.customers_list_item,customers );
setListAdapter(customerAdapter);
}
}
});
}
Post a Comment for "Arrayadapter Filter Return Wrong Items"