Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom Filtering ArrayAdapter in ListView not working for imageview
    primarykey
    data
    text
    <p>I am a begginer in Android but I tried to make a custom <code>listview</code> filtering and I it worked somehow. The only problem I have is that the <code>ArrayList</code> that I am having image view and when I search for list it works but images are displayed wrong. I can't explain this but I thought that you can help me somehow.</p> <p>Anyway here is the Custom <code>ArrayAdaptor</code> :</p> <pre><code>public class Listadapter extends ArrayAdapter&lt;HashMap&lt;String, String&gt;&gt; { ArrayList&lt;HashMap&lt;String, String&gt;&gt; originalList; ArrayList&lt;HashMap&lt;String, String&gt;&gt; productlist; private ProductFilter filter; public Listadapter(Context context, int textViewResourceId, ArrayList&lt;HashMap&lt;String, String&gt;&gt; Strings) { super(context, textViewResourceId, Strings); this.productlist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); this.productlist.addAll(productList); this.originalList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); 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; }*/ public int getCount() { return productList.size(); } public long getItemId(int position) { // return productList.indexOf(getItem(position)); return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { //ViewHolder holder = null; TextView txtprodName, txtcategory, txtOfferDate; ImageView ProductImage; 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(); txtprodName = (TextView) convertView .findViewById(R.id.txtprodName); txtcategory = (TextView) convertView .findViewById(R.id.txtcategory); txtOfferDate = (TextView) convertView .findViewById(R.id.txtOfferDate); ProductImage = (ImageView) convertView .findViewById(R.id.ProductImage); //convertView.setTag(holder); /*} else { //holder = (ViewHolder) convertView.getTag(); }*/ HashMap&lt;String, String&gt; hm = productList.get(position); // txtUserName.setText(lstUsers.get(position).getFirst_Name()+" "+lstUsers.get(position).getLast_Name()); txtprodName.setText(hm.get(TAG_PRODUCT_NAME)); txtcategory.setText(hm.get(TAG_CATEGORY_NAME)); txtOfferDate.setText(hm.get(TAG_OFFER_START_TIME)); if (drawable.get(position) != null) ProductImage.setImageDrawable(drawable.get(position)); else 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 &amp;&amp; constraint.toString().length() &gt; 0) { ArrayList&lt;HashMap&lt;String, String&gt;&gt; filteredItems = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); for (int i = 0, l = originalList.size(); i &lt; l; i++) { // ArrayList&lt;HashMap&lt;String, String&gt;&gt; p = // originalList.get(i); HashMap&lt;String, String&gt; 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 productList = (ArrayList&lt;HashMap&lt;String, String&gt;&gt;) results.values; notifyDataSetChanged(); clear(); for (int i = 0, l = productList.size(); i &lt; l; i++) add(productList.get(i)); notifyDataSetInvalidated(); } } </code></pre> <p>following is the result</p> <p><img src="https://i.stack.imgur.com/EJMtU.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/cIkV4.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload