我有一个列表视图,我正在使用
填充数据searchList.setAdapter(new DirectoryListAdapter());
其中DirectoryListAdapter是我的适配器扩展基础适配器。当我在其中一个items-employee_name上搜索我的搜索文本框中应该包含的内容。我厌倦了这段代码但是没有用。
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
((DirectoryListAdapter)adapter).filter(text);
}
onTextChanged方法应该包含什么。基础适配器代码 公共类DirectoryListAdapter扩展了BaseAdapter {
ViewHolder holder;
static class ViewHolder {
public TextView text;
public ImageView image;
public TextView nearestEntranceText;
}
@Override
public int getCount() {
int len = MasterData.getInstance().getTenantList().size();
return len;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView (int position, View convertView, ViewGroup parent) {
View directoryItemView = convertView;
if (directoryItemView == null) {
directoryItemView = LayoutInflater.from(parent.getContext()).inflate (R.layout.list_view_item, parent, false);
ViewHolder viewHolder = new ViewHolder ();
viewHolder.text = (TextView) directoryItemView.findViewById (R.id.itemTextView);
viewHolder.image = (ImageView) directoryItemView.findViewById (R.id.logoImageView);
viewHolder.nearestEntranceText = (TextView) directoryItemView.findViewById (R.id.closestEntranceTextView);
directoryItemView.setTag (viewHolder);
holder = viewHolder;
} else {
holder = (ViewHolder) directoryItemView.getTag();
}
TenantItem item = (TenantItem) MasterData.getInstance().getTenantList().get(position);
final String noLogoCheckStr = parent.getContext().getString (R.string.web_service_no_logo_comparsion_string);
final String fetchLink = item.getTenantLogoURL();
ListItemLayout layoutItem = (ListItemLayout) directoryItemView;
layoutItem.tenantItemObj = item;
/*
layoutItem.tenantID = item.getTenantID();
if (item.getHasMultipleEntries()) {
layoutItem.tenantIDList = item.getTenantIDList();
}
// layoutItem.tenantIDList = item.getTenantList
*/
if (fetchLink.contains (noLogoCheckStr)) {
Picasso.with (parent.getContext())
.load(R.drawable.placeholder_logo)
.into(holder.image);
} else {
Picasso.with (parent.getContext())
.load(fetchLink)
.error(R.drawable.placeholder_logo)
.into(holder.image);
}
holder.text.setText(item.getTenantName());
if (item.getHasMultipleEntries()) {
holder.nearestEntranceText.setText (R.string.tenant_multiple_location_label);
} else {
holder.nearestEntranceText.setText (item.getTenantLocation());
}
return directoryItemView;
}
}