I noticed that there is no working solution that shows how to use the filter for listView items using the action bar that works on earlier versions of Android (e.g. 2.3.x).
The only example I found is in the LoaderCursorSupport.java file of the sample fragments. However, it only works when searchView can be created, i.e. starting with Android 3.x, as shown in the code:
View searchView=SearchViewCompat.newSearchView(getActivity()); if(searchView!=null) ...
The above error (or missing function, depending on how you look at it) still exists even on version 4.2 actionBarSherlock.
So, I made my own solution, which works fine (and I want the official library to be able to add a fix to it as well), but I donβt know where to get the "x" button in the editText view, it is responsible for clearing the text.
Can someone please tell me how to get the look and put it correctly in the code?
Here is a screenshot of what I'm talking about:

For those who want to use this feature, here is my code snippet:
@Override public boolean onCreateOptionsMenu(final com.actionbarsherlock.view.Menu menu) { getSupportMenuInflater().inflate(R.menu.activity_main,menu); _searchMenuItem=menu.findItem(R.id.menu_item_action_search); View searchView=SearchViewCompat.newSearchView(this); if(searchView!=null) SearchViewCompat.setOnQueryTextListener(searchView,new OnQueryTextListenerCompat() { @Override public boolean onQueryTextChange(final String newText) { _listAdapter.getFilter().filter(newText); return true; } @Override public boolean onQueryTextSubmit(final String query) { return super.onQueryTextSubmit(query); } }); else { searchView=new EditText(this); searchView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT)); ((EditText)searchView).setHint(R.string.search); ((EditText)searchView).addTextChangedListener(new TextWatcher() { String curretTextToFilter =null; @Override public void onTextChanged(final CharSequence newText,final int start,final int before,final int count) { if(newText==curretTextToFilter) return; curretTextToFilter=newText.toString(); _listAdapter.getFilter().filter(curretTextToFilter==null||curretTextToFilter.length()==0 ? null : curretTextToFilter); } @Override public void beforeTextChanged(final CharSequence s,final int start,final int count,final int after) {} @Override public void afterTextChanged(final Editable s) {} }); } final View finalSearchView=searchView; _searchMenuItem.setOnActionExpandListener(new OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(final MenuItem item) { if(finalSearchView instanceof EditText) { final InputMethodManager m=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); finalSearchView.requestFocus(); if(m!=null) m.toggleSoftInput(0,InputMethodManager.SHOW_IMPLICIT); } return true; } @Override public boolean onMenuItemActionCollapse(final MenuItem item) { if(finalSearchView instanceof EditText) ((EditText)finalSearchView).setText(null); else _listAdapter.getFilter().filter(null); return true; } }); _searchMenuItem.setActionView(searchView);
android actionbarsherlock searchview filtering
android developer
source share