Add android:imeoptions= "Actionsearch" to the input box, and when you call the soft keyboard, the ENTER key will display the search word.
I want to jump to the next page when I click on the search, but call Setonkeylistener and execute two times each time. Finally on the Internet to see other people's articles, solve the problem, the solution is to call Setoneditoractionlistener instead of using Setonkeylistener to listen to click the Search button.
The code is as follows (written in fragment, remove context-related things when writing in the activity):
Searchtext.setoneditoractionlistener (New Oneditoractionlistener () {
@Override
public boolean oneditoraction (TextView v, int ActionId, keyevent event) {
if (ActionId ==editorinfo.ime_action_search) {
Hide the keyboard first
((Inputmethodmanager) Searchtext.getcontext (). Getsystemservice (Context.input_method_service))
. Hidesoftinputfromwindow (
Getactivity ()
. Getcurrentfocus ()
. Getwindowtoken (),
Inputmethodmanager.hide_not_always);
Jump activity
Intent Intent = new Intent ();
Intent.setclass (Getactivity (), searchresultactivity.class);
StartActivity (Intent);
Inserting the queried data into the database
Mdbhelper.insert_search_history (Searchtext.gettext (). toString (), getstringdate ());
return true;
}
return false;
}
});
Android Settings soft keyboard search key and listen to the search button click on the issue occurred two times the problem solved