关于 edittext 软键盘退出监听解决办法

edittext 有个onCreateInputConnection 的方法,通过它可以自定义一个输入法连接器,那里连接器里面有个方法(finishComposingText)能监听输入完成的动作.

public class MyEditText extends EditText{  
   
        public MyEditText(Context context) {  
                super(context);  
        }   
        private OnFinishComposingListener mFinishComposingListener;  
           
        public void setOnFinishComposingListener(OnFinishComposingListener listener){  
                this.mFinishComposingListener =listener;  
        }   
        @Override  
        public InputConnection onCreateInputConnection(EditorInfo outAttrs) {  
                return new MyInputConnection(super.onCreateInputConnection(outAttrs), false);  
        }    
        public class MyInputConnection extends InputConnectionWrapper {  
                public MyInputConnection(InputConnection target, boolean mutable) {  
                        super(target, mutable);  
                }  
                @Override  
               public boolean finishComposingText() {  
                        boolean finishComposing = super.finishComposingText();  
                        if(mFinishComposingListener != null){  
                                mFinishComposingListener.finishComposing();  
                        }  
                        return finishComposing;  
                }  
        }     
        public interface OnFinishComposingListener{  
                public void finishComposing();  
        }  
}  

 

posted on 2015-06-15 19:15  行殇  阅读(636)  评论(0编辑  收藏  举报

导航