Androidがオンスクリーンキーボードの完了キーの押下を検出する


111

Doneオンスクリーンキーボードのキーが押されたことを検出することはできますか?

回答:


276

はい、可能です:

editText = (EditText) findViewById(R.id.edit_text);

editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            // do your stuff here
        }
        return false;
    }
});

次のライブラリをインポートする必要があることに注意してください。

import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;

ありがとう、あなたは私に素晴らしい出発点を与えました。EditorInfo.IME_ACTION_SEARCH代わりにレンズ検索ボタンを使用する必要がありました。
TechNyquist 2015

こんにちは、バターナイフでこれは可能ですか?@ mikeyaworski @ SzabolcsBerecz
Maulik Dodia

1
@MaulikDodiaバターナイフの@OnEditorAction()を使用できます
Ridcully

ありがとうございます。it @ Ridcully
Maulik Dodia

3

Editor Infoは、Androidアプリケーションで任意のタイプのユーザー入力を処理する必要がある場合に最も便利なクラスです。たとえば、ログイン/登録/検索操作では、より正確なキーボード入力に使用できます。エディター情報クラスは、インプットメソッドがエディットテキストコンテンツと直接通信するテキスト編集オブジェクトのいくつかの属性を記述します。

IME_ACTION_DONEで試すことができます。

このアクションは、Done何も入力せずに操作を実行し、IMEが閉じられます。

setOnEditorActionListenerの使用

EditTextObj.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        boolean handled = false;
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            /* Write your logic here that will be executed when user taps next button */
            handled = true;
        }
        return handled;
    }
});

カスタムキーボードで同じ問題をどのように処理しますか?
Gaju Kollur

0

バターナイフを使用すると、これを行うことができます

@OnEditorAction(R.id.signInPasswordText)
boolean onEditorAction(TextView v, int actionId, KeyEvent event){
    if (actionId == EditorInfo.IME_ACTION_DONE || event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
        /* Write your logic here that will be executed when user taps next button */
    }
    return false;
}
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.