我对自定义对象的过滤数组适配器有问题。 我对 String () 使用 owerride 自定义对象, 所以它返回了名称, 我想要过滤。 问题在于它的文件员更正了项目数, 但错误的项目数。 例如, 我有一个列表中的项目 a1, a2, b1, b1, b2 。 当我输入 b 过滤器, 我看到 a1, a2 时, 我有一个调适器代码。 我想问题在于 :
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);