This is my solution and it works really well for me, but everyones needs are different.
First i subclassed EditText and hooked up a listener (Google should make this the default)
public class ListenerEditText extends EditText {
private KeyImeChange keyImeChangeListener;
public ListenerEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setKeyImeChangeListener(KeyImeChange listener){
keyImeChangeListener = listener;
}
public interface KeyImeChange {
public void onKeyIme(int keyCode, KeyEvent event);
}
@Override
public boolean onKeyPreIme (int keyCode, KeyEvent event){
if(keyImeChangeListener != null){
keyImeChangeListener.onKeyIme(keyCode, event);
}
return false;
}
}
Then you can attach a listener from anywhere like so:
myListenerEditText.setKeyImeChangeListener(new KeyImeChange() {
@Override
public void onKeyIme(int keyCode, KeyEvent event) {
// All keypresses with the keyboard open will come through here!
// You could also bubble up the true/false if you wanted
// to disable propagation.
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…