Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't need to implement your own filter... just override getFilter as @Waqas suggested.</p> <p>Here's what I did and it works. Feel free to adjust it to your needs...</p> <p>Hope it'll help.</p> <p><strong>The EditText (searchFilder):</strong></p> <pre><code>searchFilter.addTextChangedListener(mOnSearchBoxTextChanged); private TextWatcher mOnSearchBoxTextChanged = new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { mAdapter.getFilter().filter(s.toString()); } }; </code></pre> <p><strong>The Adapter getFilter():</strong></p> <pre><code> class MyAdapter extends BaseAdapter implements Filterable { //the rest of the adapter.... @Override public Filter getFilter() { if (newFilter == null) { newFilter = new Filter() { @Override protected void publishResults(CharSequence prefix, FilterResults results) { CLog.logD( "Friends list filtered"); mAdapter.notifyDataSetChanged(); } @Override protected FilterResults performFiltering(CharSequence constraint) { constraint = constraint.toString().toLowerCase(); filteredFriendList = new ArrayList&lt;FriendsListItemView&gt;(); if (constraint!= null &amp;&amp; constraint.toString().length() &gt; 0) { for (int i = 0; i &lt; friendsList.size(); i++) { FriendsListItemView newFriend = friendsList.get(i); String name = newFriend.userName.getText().toString(); if (name.toLowerCase().contains(constraint)) { filteredFriendList.add(newFriend); } } } else { if (filteredFriendList.size() == 0) { filteredFriendList = friendsList; } } FilterResults newFilterResults = new FilterResults(); newFilterResults.count = filteredFriendList.size(); newFilterResults.values = filteredFriendList; return newFilterResults; } }; } return newFilter; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      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