Note that there are some explanatory texts on larger screens.

plurals
  1. POFilter a Listview using a spinner in android
    primarykey
    data
    text
    <p>I have this Listview that contains both text and images. Each list item contains four key elements. I want to be able to filter the listview using either of the three TextViews by an option selected from the spinner. This is what I have done so far:</p> <pre><code> public class LazyVenueAdapter extends BaseAdapter implements Filterable { private Activity activity; private ArrayList&lt;HashMap&lt;String, String&gt;&gt; data; private static LayoutInflater inflater = null; public ImageLoader imageLoader; public LazyVenueAdapter(Activity a, ArrayList&lt;HashMap&lt;String, String&gt;&gt; d) { activity = a; data = d; inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); imageLoader = new ImageLoader(activity.getApplicationContext()); } public int getCount() { return data.size(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } @Override public void notifyDataSetChanged() { super.notifyDataSetChanged(); } public View getView(int position, View convertView, ViewGroup parent) { View vi = convertView; if (convertView == null) vi = inflater.inflate(R.layout.venue_list_item, null); TextView title = (TextView) vi.findViewById(R.id.venueName); TextView location = (TextView) vi.findViewById(R.id.venueLocation); TextView tags = (TextView) vi.findViewById(R.id.venueTags); ImageView thumb_image = (ImageView) vi.findViewById(R.id.venueImage); HashMap&lt;String, String&gt; venue = new HashMap&lt;String, String&gt;(); venue = data.get(position); // Setting all values in listview title.setText(venue.get(VenuesFragment.KEY_TITLE)); location.setText(venue.get(VenuesFragment.KEY_LOCATION)); tags.setText(venue.get(VenuesFragment.KEY_TAGS)); imageLoader.DisplayImage(venue.get(VenuesFragment.KEY_THUMB_URL), thumb_image); return vi; } @Override public Filter getFilter() { Filter filter = new Filter() { @Override protected FilterResults performFiltering(CharSequence constraint) { FilterResults results = new FilterResults(); ArrayList&lt;HashMap&lt;String, String&gt;&gt; filteredArrayVenues = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); data.clear(); if (constraint == null || constraint.length() == 0) { results.count = data.size(); results.values = data; } else { constraint = constraint.toString(); for (int index = 0; index &lt; data.size(); index++) { HashMap&lt;String, String&gt; dataVenues = data.get(index); if (dataVenues.get(VenuesFragment.KEY_TAGS).toString().startsWith( constraint.toString())) { filteredArrayVenues.add(dataVenues); } } results.count = filteredArrayVenues.size(); System.out.println(results.count); results.values = filteredArrayVenues; Log.e("VALUES", results.values.toString()); } return results; } @SuppressWarnings("unchecked") @Override protected void publishResults(CharSequence constraint, FilterResults results) { data = (ArrayList&lt;HashMap&lt;String, String&gt;&gt;) results.values; notifyDataSetChanged(); } }; return filter; } } </code></pre> <p>The problem that I am having is that when I select an option from the drop down list I get back an empty result set.</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.
    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