Implicit “Submit” after hitting Done on the keyboard at the last EditText

前端 未结 10 631
无人及你
无人及你 2020-11-29 17:51

I\'ve used some apps where when I fill my username, then go to my password, if I hit \"Done\" on the keyboard, the login form is automatically submitted, without me having t

10条回答
  •  猫巷女王i
    2020-11-29 18:27

    Try this:

    In your layout put/edit this:

    
    

    In your activity put this (e. g. in onCreate):

     // your text box
     EditText edit_txt = (EditText) findViewById(R.id.search_edit);
    
     edit_txt.setOnEditorActionListener(new EditText.OnEditorActionListener() {
         @Override
         public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
             if (actionId == EditorInfo.IME_ACTION_DONE) {
                 submit_btn.performClick();
                 return true;
             }
             return false;
         }
     });
    

    Where submit_btn is your submit button with your onclick handler attached.

提交回复
热议问题