How can I build a search bar where while I'm typing the results are shown in the ListView
in which I'm searching?
For example, I have a list view with 20 strings. I press the search key and appears the bar. I want when I type 3 words or more the search starts running showing the results in the list view (as a filter: only shows the strings in the list that matching what I type)
You can add voice search functionality to your search dialog or widget by adding the android:voiceSearchMode attribute to your searchable configuration. This adds a voice search button that launches a voice prompt.
To get the Google Search bar widget back on your screen, follow the path Home Screen > Widgets > Google Search. You should then see the Google Search bar reappear on your phone's main screen.
just do your own search view, it is very simple. you then can include this layout in your activity layout file. This is a simple layout which includes a "search icon" followed by EditText, followed by "clear icon". The clear icon is shown after user types some text.
create some array list for the listview .. And on "AddTextChangeListener" you can search for similar items in the list and load a new arraylist for the searched text... Show activity on this post. The below code uses a custom list adapter.
I believe this is what you are looking for:
http://www.java2s.com/Code/Android/2D-Graphics/ShowsalistthatcanbefilteredinplacewithaSearchViewinnoniconifiedmode.htm
Have your Activity implement SearchView.OnQueryTextListener
and add the following methods:
public boolean onQueryTextChange(String newText) { if (TextUtils.isEmpty(newText)) { mListView.clearTextFilter(); } else { mListView.setFilterText(newText.toString()); } return true; } public boolean onQueryTextSubmit(String query) { return false; }
You can't do this with the search bar. But the listview has a possibility to filter on key pressed, like it is done in the contacts. The user simply starts typing and the list gets filtered then. Filtering is not really like searching. If you list contains the word foo somewhere and you type oo foo will be filtered out, but if you type fo it will stay even if the list item is call bar foo.
You simply have to enable it:
ListView lv = getListView(); lv.setTextFilterEnabled(true);
I don't know how this is done if you don't have a hardware keyboard. I'm using the droid and starting to type starts the list to filter and to show only matching results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With