简体   繁体   中英

Hide search/go button on soft keyboard when using search View?

I have implemented search view for my application. When i try to query i show results using Listview and want use to select one of them. If not available list will be empty. However people can click search icon/go in soft keyboard i want to hide that button.

I want user to select values from suggestions only and not search separately

How can we achieve this?

Just prevent the user from using the button whenever the value is not in your list. To do that you can just handle the clicking of the enter button.

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
            if(isTextInList())
               return true;
            return false;
        default:
            return super.onKeyUp(keyCode, event);
    }
}

for more info: http://developer.android.com/training/keyboard-input/commands.html#SingleKey

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM