如果你没有接第三方的输入设备,那么点击按钮只需找到你的button然后:button.performClick();
就可以了
那么如果你用到第三方输入法,有些时候监听就没有这么好使了:
以下场景为:
外接输入服务,直接给我丢一串字符,我拿到字符后执行按钮事件
代码如下:editText1.addTextChangedListener(newTextWatcher(){
@Override
publicvoidafterTextChanged(Editables){
Log.d(TAG,"afterTextChanged");
}
@Override
publicvoidbeforeTextChanged(CharSequences,intstart,intcount,
intafter){
Log.d(TAG,"beforeTextChanged:"+s+"-"+start+"-"+count+"-"+after);
}
@Override
publicvoidonTextChanged(CharSequences,intstart,intbefore,
intcount){
if(s.length()>5){
Log.d(TAG,"onTextChanged:"+s+"-"+"-"+start+"-"+before+"-"+count);
Toast.makeText(context,s+"",Toast.LENGTH_LONG).show();
//
EditTexteditText3=(EditText)findViewById(R.id.et_3);
Buttonbutton=(Button)findViewById(R.id.bu_1);
button.performClick();
}
}
});
需要注意的是,onTextChanged
方法内必须给一个限定参数,否则会不断的执行,形成死循环,程序就会意外退出。
我这边写的则是if(s.length()>5)