How to search with enter key on android custom InputMethodService?
<p>I want to search with my android custom keyboard with the enter key, but it does not work.<br/>
I've already mapped the keys, I just need to trigger the "search action" on a search text field, just like searching on google.</p>

<p>I tried this code for triggering the search action, but it doesn't work:</p>

<pre><code>ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
</code></pre>

<p>Here is my method for overwriting the enter key event:</p>

<pre><code>public class Keyboard extends InputMethodService
    implements KeyboardView.OnKeyboardActionListener {

@Override
public void onStartInputView(EditorInfo info, boolean restarting) {
    super.onStartInputView(info, restarting);

    setInputView(onCreateInputView());

    switch (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION) {

        case EditorInfo.IME_ACTION_SEARCH:
            Toast.makeText(this, "test", Toast.LENGTH_SHORT).show();
            //Action Search
            break;
    }
}
</code></pre>

<p>My xml layout is:<br/></p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;android.inputmethodservice.KeyboardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/keyboard"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:keyPreviewHeight="60dp"
    android:keyPreviewOffset="12dp"
    android:keyPreviewLayout="@layout/preview"
    android:visibility="visible"/&gt;
</code></pre>

<p>I don't have any EditText in my layout to set <code>android:imeOptions="actionSearch"</code>.</p>