19

EditTextがあります。クリックするとピントが合います。EditTextに入力する入力テキストを入力します。EditTextのリスナーを実装したいので、入力を停止すると、ボタンを使用する代わりに、そのテキストをデータベースに自動的に保存する必要があります。EditTextのリスナーに、入力が停止されているかどうかをリッスンさせるにはどうすればよいですか?

4

4 に答える 4

60

このようにしてみてください。

EditText et = (EditText)findViewById(R.id.editText);
Log.e("TextWatcherTest", "Set text xyz");
et.setText("xyz");

et.addTextChangedListener(new TextWatcher() {
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) { }
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
    @Override
    public void afterTextChanged(Editable s) {
        Log.e("TextWatcherTest", "afterTextChanged:\t" +s.toString());
    }
});
于 2012-01-02T10:13:42.400 に答える
18

set edittext imeOption

editText.setImeOptions(EditorInfo.IME_ACTION_DONE);

By using something like this,

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

Alternatively, you can use the OnEditorActionListener interface to avoid the anonymous inner class.

于 2012-05-16T13:03:51.520 に答える