mobile menu
Site icon
ZidsWorld

The Tech Galaxy

Live support

android logo

How to set Text in SearchView Programmatically in Android

Monday, March 4, 2024, 5 PM

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 do it

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.