사용자 지정 개체로 배열 어댑터를 필터링하는 데 문제가 있습니다. 내가 owerride 사용자 정의 개체 toString() 그래서 그것은 필터를 원하는 이름을 반환합니다. 문제는 올바른 개수의 항목이지만 잘못된 항목이있는 것입니다. 예 : 아이템 a1, a2, b1, b2가있는 목록이 있습니다. 내가 필터에 들어가면 a1, a2가 보입니다. 다음은 어댑터 코드입니다. 나는 문제가있는 것 같아요 :ArrayAdapter 필터가 잘못된 항목을 반환합니다.
class CustomerAdapter extends ArrayAdapter<Customer> {
private LayoutInflater mInflater;
private List<Customer> customers;
public CustomerAdapter(Context context, int textViewResourceId,
List<Customer> customers) {
super(context, textViewResourceId, customers);
mInflater = LayoutInflater.from(context);
this.customers = customers;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.customers_list_item, null);
holder = new ViewHolder();
holder.text = (TextView) convertView
.findViewById(R.id.textViewCustomerName);
holder.icon = (LinearLayout) convertView
.findViewById(R.id.linearLayoutCustomersListEdit);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
// Bind the data efficiently with the holder.
holder.text.setText(customers.get(position).getCustomerName());
return convertView;
}
static class ViewHolder {
TextView text;
LinearLayout icon;
}
} 여기
필터 설정 및 호출 할 수 있습니다 :
customerAdapter = new CustomerAdapter(this,
R.layout.customers_list_item, repository.getCustomers());
setListAdapter(customerAdapter);
etSearch = (EditText) findViewById(R.id.editText_customers_search);
etSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int arg1, int arg2,
int arg3) {
customerAdapter.getFilter().filter(s.toString());
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
}
@Override
public void afterTextChanged(Editable arg0) {
}
});
getListView().setTextFilterEnabled(true);
당신이 필터를 교체 할 수 있도록 getFilter 메소드를 오버라이드 (override) 할 필요가 있다고 생각 행동과 자신의 필터링을 만들 –