Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's what you do. It's also hidden in the Android Developer's sample code 'Bluetooth Chat'. Replace the bold parts that say <strong>"example"</strong> with your own variables and methods.</p> <p>First, import what you need into the main Activity where you want the return button to do something special:</p> <pre><code>import android.view.inputmethod.EditorInfo; import android.widget.TextView; import android.view.KeyEvent; </code></pre> <p>Now, make a variable of type TextView.OnEditorActionListener for your return key (here I use <strong>exampleListener</strong>);</p> <pre><code>TextView.OnEditorActionListener exampleListener = new TextView.OnEditorActionListener(){ </code></pre> <p>Then you need to tell the listener two things about what to do when the return button is pressed. It needs to know what EditText we're talking about (here I use <strong>exampleView</strong>), and then it needs to know what to do when the Enter key is pressed (here, <strong>example_confirm()</strong>). If this is the last or only EditText in your Activity, it should do the same thing as the onClick method for your Submit (or OK, Confirm, Send, Save, etc) button.</p> <pre><code>public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_NULL &amp;&amp; event.getAction() == KeyEvent.ACTION_DOWN) { example_confirm();//match this behavior to your 'Send' (or Confirm) button } return true; } </code></pre> <p>Finally, set the listener (most likely in your onCreate method);</p> <pre><code>exampleView.setOnEditorActionListener(exampleListener); </code></pre>
    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