Providing Search with SearchView (Android Development Patterns Ep 7)
Why Stack Overflow recommends it
Stack Overflow users link it when answering SearchView questions, such as setting up the searchable configuration, using showAsAction with collapseActionView, or listening for queries in the same activity.
Recommended by 2 people across 3 different months, 2016 to 2021.
What it is
A short Android Developers tutorial from the Android Development Patterns series on adding in-app search with SearchView from AppCompat. It covers searchable configuration, voice search, and handling queries, with pointers to full-text search tables and query suggestions.
What people said
Recommends ianhanniballake · 2016-02 · Stack Overflow · on “SearchView launches searchable activity without intent”
I brought it up in the Providing Search with SearchView video [this video] at 4 minutes in [this video] . Still working on updating the documentation (or at least having a link to the video added!)
Recommends ianhanniballake · 2016-02 · Stack Overflow · on “Creating Material Design SearchView which is always collapsed”
You have to use app:showAsAction="always|collapseActionView" If you want it to always show, but be expandable as explained in the action views training [LINK] and the Providing Search with SearchView video [this video]
Recommends ianhanniballake · 2016-07 · Stack Overflow · on “Why does SearchView require two activities?”
Yes, you can certainly implement it in the same activity. As per the Providing Search with SearchView video [this video] , you can use the setOnQueryTextListener() method [LINK] to directly listen for text changes or when the user submits the search (skipping the need for a searchable configuration at all). If you do want to use the searchable configuration, make sure your activity uses android:launchMode="singleTop" as per later in the same video [this video] . This prevents many copies of the activity from being created on top of one another.
Recommends GeekAbout · 2021-02 · Stack Overflow · on “SearchView is not showing”
Could you run it and show compilation or run errors? I think, I don't get the problem fully. Here's some tips for menus: When you are starting you can use app:showAsAction="always" In that case small icon, which you choose should apesr in the app bar. So you can do it to chcech if image appears at all (to learn). Second of all - probably program have a problem to find a SearchView, because you forgot to add "app:actionVieClass". In that case your code should throw error during calling this line (SearchView) item.getActionVie(). Checkout this video - maybe it will be helpfull: [this video]
Cites vanlooverenkoen · 2016-04 · Stack Overflow · on “Can't get SearchView in actionbar to work”
I have tried a lot of tutorials, stackoverflow solutions, and the google tutorial -> [this video] but I can't get the searchview in my actionbar to work. does anyone sees what I am doing wrong? I Always get a nullpointerexception on the searchView My Activity with the listview: @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.list_menu, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setOnQueryTextListener( new SearchView.OnQueryTextListener() { @Override public boolean onQueryTe
Cites Magnus E-F · 2017-08 · Stack Overflow · on “Android Search menu item disappears when pressing back button/collapsing search field”
I'm using android SearchView to have a search button in my action bar. I followed this [this video] tutorial from Google Developers on YouTube, and added a few tweaks based on my own needs. However, whenever I exit the search field that comes up when clicking the button, the search button disappears! Here is my onCreateOptionsMenu and onOptionsItemSelected functions onCreateOptionsMenu: @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } onOptionsItemSelected: @Override public boolean onOptionsItemSelected(final MenuItem item) { // Handle action bar item
Cites Evren Yurtesen · 2017-12 · Stack Overflow · on “When configuring an Android search widget, what do you do if the the current activity is not the searchable activity?”
I know it is really late but I was having same problem and solution is to NOT use getComponentName() Instead you should use: // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName componentName = new ComponentName(this, SearchableActivity.class); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(componentName)); Source: [this video] At: 3:50