android軟鍵盤的事件響應:android EditText inputType 及 android:imeOptions=”actionDone”
inputKey = (EditText) findViewById(R.id.contactSearch_editText);
inputKey.addTextChangedListener(watcher);
inputKey.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (KeyEvent.KEYCODE_ENTER == keyCode && event.getAction() == KeyEvent.ACTION_DOWN) {
handler.post(updateView);
return true;
}
return false;
}
});
//響應鍵盤內容
public TextWatcher watcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2,int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
handler.post(updateView);
}
};