Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

submit a query when click on search button in keyboard

I have search view in my fragment. when I click on it , keyboard is open and I can type text. I want when I click on search button in keyboard , my query send to my server and get result but I don't know how get search event. any solution?enter image description here

like image 629
Saber Solooki Avatar asked Jul 09 '14 19:07

Saber Solooki


People also ask

What is Search button in keyboard?

The keystroke combination for searching for text within a message was Ctrl / Command + F, Ctrl / Command + F. (That is, the same key combination used twice in a row.)

How do I use search view?

Android SearchView provides user interface to search query submitted over search provider. SearchView widget can be implemented over ToolBar/ActionBar or inside a layout. SearchView is by default collapsible and set to be iconified using setIconifiedByDefault(true) method of SearchView class.

How do I close the keyboard on Android?

HIDE_IMPLICIT_ONLY, 0); Here pass HIDE_IMPLICIT_ONLY at the position of showFlag and 0 at the position of hiddenFlag . It will forcefully close soft Keyboard.


1 Answers

You have to extend OnQueryTextListener, attach the listener and implement onQueryTextSubmit.

Example:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    searchView = (SearchView) menu.findItem(R.id.mActionSearch).getActionView();
    searchView.setOnQueryTextListener(this);

    return true;
}   

@Override
public boolean onQueryTextSubmit(String query) {
    //Do something here
    return false;
}

@Override
public boolean onQueryTextChange(String newText) {
    return false;
}
like image 119
Pozzo Apps Avatar answered Oct 18 '22 18:10

Pozzo Apps