Set Text in SearchView Programmatically in Java Android

Here is how to set text searchquery in a searchview and submit in android studio java

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

Related Posts

Add Admob ads in recyclerview in android

How to add admob native ads to recyclerview in android java Adding admob native ads into android recyclerview isn’t easy like other admob ads. You will need…

Download WebView Flutter Source Code for Android and iOS

Easily create android and iOS WebView app for your websites, the much-awaited flutter WebView source code is here. Are you looking for a flutter WebView source code…

Fix uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:_flutter_android]

This error can be fixed by modifying build.gradle file in the flutter In android studio: go to android>app>build.gradle and modify it as follows:

Get Your Own Android Mobile App for Your Website Today

Are you looking to expand your online presence and reach more customers? In today’s digital age, having a mobile app is an essential tool to connect with…

Why making an app for your website can help your business to grow

In today’s digital age, it’s more important than ever to have a strong online presence. Whether you’re running a business, a blog, or a personal website, having…

Fix android.content.Intent.migrateExtraStreamToClipData(android.content.Context)’ on a null object reference

Here is how to Fix Android Studio Error Attempt to invoke virtual method ‘boolean android.content.Intent.migrateExtraStreamToClipData(android.content.Context)’ on a null object reference This error is caused by a number…

Leave a Reply

Your email address will not be published. Required fields are marked *