So if you are using a searchview in you project and want to show the suggestions you can implement there two methods
/**
* Called when the user submits the query. This could be due to a key press on the
* keyboard or due to pressing a submit button.
* The listener can override the standard behavior by returning true
* to indicate that it has handled the submit request. Otherwise return false to
* let the SearchView handle the submission by launching any associated intent.
*
* @param query the query text that is to be submitted
*
* @return true if the query has been handled by the listener, false to let the
* SearchView perform the default action.
*/
boolean onQueryTextSubmit(String query);
/**
* Called when the query text is changed by the user.
*
* @param newText the new content of the query text field.
*
* @return false if the SearchView should perform the default action of showing any
* suggestions if available, true if the action was handled by the listener.
*/
boolean onQueryTextChange(String newText);
As you can see from the documentation how these methods work.
So as long as user is typing onQueryTextChange method will be called and every time new keyword is entered or deleted it will be called.
In this method you can call the server to get the suggestions and give that to user.
Now if user wants to search for eg. "apple" so it won't make sense to hit server for every keyword, like hit server for "a" then "ap" after that "app" and so on,
so it would be better to hit server once user stops typing in the searchview which you can handle using handler and runnable something like this.
Handler mHandler;
String mQueryText;
@Override
public boolean onQueryTextChange(final String newText) {
mQueryText=newText;
//Make if invisible once you get the data.
mProgressBar.setVisibility(View.VISIBLE);
mHandler.removeCallbacks(mRunnable);
mHandler.postDelayed(mRunnable,200);
return true;
}
private Runnable mRunnable =new Runnable() {
@Override
public void run() {
//Hit server here.
}
};
While you can hitting the server and getting the data you can show progress bar or something.
You can apply the same logic with the EditText https://developer.android.com/reference/android/widget/EditText.html.
Hope it helps.