300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > android按钮怎么事件监听 android 通过监听edittext实现button的点击事件

android按钮怎么事件监听 android 通过监听edittext实现button的点击事件

时间:2019-05-26 08:56:48

相关推荐

android按钮怎么事件监听 android 通过监听edittext实现button的点击事件

如果你没有接第三方的输入设备,那么点击按钮只需找到你的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)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。