Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hardware keyboards always yield enter events, but software keyboards return different actionIDs and nulls in singleLine EditTexts. This code responds every time the user presses enter in an EditText that this listener has been set to, regardless of EditText or keyboard type.</p> <pre><code>import android.view.inputmethod.EditorInfo; import android.view.KeyEvent; import android.widget.TextView.OnEditorActionListener; listener=new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (event==null) { if (actionId==EditorInfo.IME_ACTION_DONE); // Capture soft enters in a singleLine EditText that is the last EditText. else if (actionId==EditorInfo.IME_ACTION_NEXT); // Capture soft enters in other singleLine EditTexts else return false; // Let system handle all other null KeyEvents } else if (actionId==EditorInfo.IME_NULL) { // Capture most soft enters in multi-line EditTexts and all hard enters. // They supply a zero actionId and a valid KeyEvent rather than // a non-zero actionId and a null event like the previous cases. if (event.getAction()==KeyEvent.ACTION_DOWN); // We capture the event when key is first pressed. else return true; // We consume the event when the key is released. } else return false; // We let the system handle it when the listener // is triggered by something that wasn't an enter. // Code from this point on will execute whenever the user // presses enter in an attached view, regardless of position, // keyboard, or singleLine status. if (view==multiLineEditText) multiLineEditText.setText("You pressed enter"); if (view==singleLineEditText) singleLineEditText.setText("You pressed next"); if (view==lastSingleLineEditText) lastSingleLineEditText.setText("You pressed done"); return true; // Consume the event } }; </code></pre> <p>The default appearance of the enter key in singleLine=false gives a bent arrow enter keypad. When singleLine=true in the last EditText the key says DONE, and on the EditTexts before it it says NEXT. By default, this behavior is consistent across all vanilla, android, and google emulators. The scrollHorizontal attribute doesn't make any difference. The null test is important because the response of phones to soft enters is left to the manufacturer and even in the emulators, the vanilla Level 16 emulators respond to long soft enters in multi-line and scrollHorizontal EditTexts with an actionId of NEXT and a null for the event.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload