SearchView doesn't capture "ENTER" from keyboard or keypad

user7655804

Sorry to bother the community. But can I get a pointer here? I am new to programming and just learning.

I added SearchView to my toolbar, like so.

<item
    android:id="@+id/search"
    android:title="Search"
    android:icon="@android:drawable/ic_menu_search"
    app:actionViewClass="android.widget.SearchView"
    app:showAsAction="always" />

Then I am trying to capture the "ENTER" key from the keyboard or softkeypad for when someone is typing into the SearchView to make it "//do something"

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);

    MenuItem item = menu.findItem(R.id.search);
    SearchView searchView = (SearchView) item.getActionView();

    searchView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {

            if (event.getAction() == KeyEvent.ACTION_DOWN)
            {
                switch (keyCode)
                {
                    case KeyEvent.KEYCODE_ENTER:

                        //do something
                        //do something
                        //do something

                        return true;
                    default:
                        break;
                }
            }

            return false;
        }
    });

    return MainActivity.super.onCreateOptionsMenu(menu);

}

But my "//do something" never triggers. Can I get some help please?

Yyy

You can try below code

searchView.setOnQueryTextListener(new OnQueryTextListener() {

        @Override
        public boolean onQueryTextChange(String newText) {
            //Log.e("onQueryTextChange", "==called");
            return false;
        }

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

    });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Xcode simulator keypad doesn't appear after using keyboard

From Dev

Xcode simulator keypad doesn't appear after using keyboard

From Dev

CSS Button doesn't execute form when 'enter' pressed on keyboard

From Dev

CSS Button doesn't execute form when 'enter' pressed on keyboard

From Dev

clicking search bar doesn't promp keypad (iOS Swift)

From Dev

How can I capture keyboard status when my application doesn't have the focus?

From Dev

Keyboard doesn't work

From Dev

How to restrict the presence of the Keyboard/Keypad

From Dev

Fiddler doesn't capture traffic from remote clients on virtual machine

From Dev

UITextfield doesn't show keyboard after dismiss from presentMoviePlayerViewControllerAnimated

From Dev

In X11 SSH forwarding, keyboard isn't working properly (Only Ctrl + .. and numeric keypad works!)

From Dev

Text input in SearchView doesn't show

From Dev

SearchView Suggestion doesn't work with one character

From Dev

Searchview doesn't work since app compat

From Dev

SearchView doesn't appear in Toolbar - Android Lollipop

From Dev

SearchView doesn't expand full width

From Dev

listview searchview android doesn't do search

From Dev

SearchView doesn't show custom suggestions

From Dev

Q: Java Scanner.nextLine() from standard input throws NoSuchElementException, but 'enter' wasn't pressed on the keyboard

From Dev

Keyboard (including on screen keyboard) doesn't work

From Dev

How to enter alternative characters from extended keyboard

From Dev

Cannot enter data from keyboard in R

From Dev

.htaccess rewrites but doesn't capture

From Dev

NumberPicker doesn't work with keyboard

From Dev

Soft keyboard doesn't appear

From Dev

Soft keyboard doesn't hide

From Dev

NumberPicker doesn't work with keyboard

From Dev

Soft keyboard doesn't appear

From Dev

Soft keyboard doesn't hide

Related Related

  1. 1

    Xcode simulator keypad doesn't appear after using keyboard

  2. 2

    Xcode simulator keypad doesn't appear after using keyboard

  3. 3

    CSS Button doesn't execute form when 'enter' pressed on keyboard

  4. 4

    CSS Button doesn't execute form when 'enter' pressed on keyboard

  5. 5

    clicking search bar doesn't promp keypad (iOS Swift)

  6. 6

    How can I capture keyboard status when my application doesn't have the focus?

  7. 7

    Keyboard doesn't work

  8. 8

    How to restrict the presence of the Keyboard/Keypad

  9. 9

    Fiddler doesn't capture traffic from remote clients on virtual machine

  10. 10

    UITextfield doesn't show keyboard after dismiss from presentMoviePlayerViewControllerAnimated

  11. 11

    In X11 SSH forwarding, keyboard isn't working properly (Only Ctrl + .. and numeric keypad works!)

  12. 12

    Text input in SearchView doesn't show

  13. 13

    SearchView Suggestion doesn't work with one character

  14. 14

    Searchview doesn't work since app compat

  15. 15

    SearchView doesn't appear in Toolbar - Android Lollipop

  16. 16

    SearchView doesn't expand full width

  17. 17

    listview searchview android doesn't do search

  18. 18

    SearchView doesn't show custom suggestions

  19. 19

    Q: Java Scanner.nextLine() from standard input throws NoSuchElementException, but 'enter' wasn't pressed on the keyboard

  20. 20

    Keyboard (including on screen keyboard) doesn't work

  21. 21

    How to enter alternative characters from extended keyboard

  22. 22

    Cannot enter data from keyboard in R

  23. 23

    .htaccess rewrites but doesn't capture

  24. 24

    NumberPicker doesn't work with keyboard

  25. 25

    Soft keyboard doesn't appear

  26. 26

    Soft keyboard doesn't hide

  27. 27

    NumberPicker doesn't work with keyboard

  28. 28

    Soft keyboard doesn't appear

  29. 29

    Soft keyboard doesn't hide

HotTag

Archive