So, if you use searchview in your project and want to show suggestions, you can implement two methods there
boolean onQueryTextSubmit(String query); boolean onQueryTextChange(String newText);
As you can see from the documentation, how these methods work. Thus, while the user enters the onQueryTextChange method, it is also called every time a new keyword is entered or deleted, it will be called.
In this method, you can call the server to receive offers and give it to the user.
Now, if the user wants to search, for example. "apple", so it makes no sense to hit the server for each keyword, for example, for server "a", and then "ap" after this "application", etc.,
therefore, it would be better to attack the server as soon as the user stops typing in the search box, which you can handle using the handler and doing something like this.
Handler mHandler; String mQueryText; @Override public boolean onQueryTextChange(final String newText) { mQueryText=newText;
While you can hit the server and receive data, you can show a progress bar or something else.
You can apply the same logic to EditText https://developer.android.com/reference/android/widget/EditText.html . Hope this helps.
Reyansh mishra
source share