我正在过滤列表视图,我在其中过滤来自本地主机的数据和图像...在其中过滤了数据但未过滤图像。当我搜索该数据时,但图像来自其原始位置意味着图像来自其原始位置......
public class Listadapter extends ArrayAdapter<HashMap<String, String>> {
ArrayList<HashMap<String, String>> originalList;
ArrayList<HashMap<String, String>> prodlist;
private ProductFilter filter;
public Listadapter(Context context, int textViewResourceId,
ArrayList<HashMap<String, String>> Strings) {
super(context, textViewResourceId, Strings);
this.prodlist = new ArrayList<HashMap<String, String>>();
this.prodlist.addAll(productList);
this.originalList = new ArrayList<HashMap<String, String>>();
this.originalList.addAll(productList);
}
@Override
public Filter getFilter() {
if (filter == null) {
filter = new ProductFilter();
}
return filter;
}
private class ViewHolder {
TextView txtprodName;
TextView txtcategory;
TextView txtOfferDate;
ImageView ProductImage;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
Log.v("ConvertView", String.valueOf(position));
if (convertView == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.product_list_item, null);
holder = new ViewHolder();
holder.txtprodName = (TextView) convertView
.findViewById(R.id.txtprodName);
holder.txtcategory = (TextView) convertView
.findViewById(R.id.txtcategory);
holder.txtOfferDate = (TextView) convertView
.findViewById(R.id.txtOfferDate);
holder.ProductImage = (ImageView) convertView
.findViewById(R.id.ProductImage);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
HashMap<String, String> hm = prodlist.get(position);
holder.txtprodName.setText(hm.get(TAG_PRODUCT_NAME));
holder.txtcategory.setText(hm.get(TAG_CATEGORY_NAME));
holder.txtOfferDate.setText(hm.get(TAG_OFFER_START_TIME));
if (drawable.get(position) != null)
holder.ProductImage.setImageDrawable(drawable.get(position));
else
holder.ProductImage.setImageResource(R.drawable.nopic_place);
return convertView;
}
private class ProductFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
constraint = constraint.toString().toLowerCase();
FilterResults result = new FilterResults();
if (constraint != null && constraint.toString().length() > 0) {
ArrayList<HashMap<String, String>> filteredItems = new ArrayList<HashMap<String, String>>();
for (int i = 0, l = originalList.size(); i < l; i++) {
HashMap<String, String> p = originalList.get(i);
if (p.toString().toLowerCase().contains(constraint))
filteredItems.add(p);
}
result.count = filteredItems.size();
result.values = filteredItems;
} else {
synchronized (this) {
result.values = originalList;
result.count = originalList.size();
}
}
return result;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
// TODO Auto-generated method stub
prodlist = (ArrayList<HashMap<String, String>>) results.values;
notifyDataSetChanged();
clear();
for (int i = 0, l = prodlist.size(); i < l; i++)
add(prodlist.get(i));
notifyDataSetInvalidated();
}
}
}