mobile menu
Site icon
ZIDSWORLD

The Tech Galaxy

Live support

Set Text in SearchView Programmatically in Java Android

Friday, November 17, 2023, 8 AM

Setting text in a searchview helps to load an already created query, for example - imagine you have a wallpaper app, you want search for love wallpapers, so you usually type "love" in searchview and clicks the submit.

But what if you can set that love text programmatically in that searchview? and align it to a button click, like drawer menu, option menu etc? then your users can just search predefined keywords without typing.

Here is how to set text automatically in the search view text input field

Setting text automatic in the searchview text input field on android java

 
SearchView searchView = (SearchView) searchMenuItem.getActionView();
           String love = "love";
          searchView.setQuery(love, true);

This is it, just hook up this code with a button

Comments

No comments found.