EditText监听

这里记录几个能用得上的监听,FOR EditText:

EditText继承自TextView,TextView继承自android.view.View

      继承自android.view.View 的方法setOnKeyListener,文档说明是Register a callback to be invoked when a hardware key is pressed in this view.大概意思是说监听android设备上的输入按钮,不过现在手机都是触屏,没按钮了。经测试发现能监听文本框输入,不过不靠谱,软键盘某些按钮会必然响应,某些不响应,当软键盘启动时,按钮输入效果监听和软键盘一样了。
   继承自TextView的方法

   继承自TextView的方法addTextChangedListener(TextWatcher watcher)可以用来监听文本框输入的变化,当EditText里面有输入变化时触发此监听,需重写3个方法,对应,变化前 beforeTextChanged(CharSequence s, int start, int count,int after),变化onTextChanged(CharSequence s, int start, int before, int count),变化后afterTextChanged(Editable s)。用此方法可以很好的监听文本输入框的变化并针对输入变化进行处理。

     继承自TextView的方法setOnEditorActionListener(TextView.OnEditorActionListener l)可以监听回车键,

可以对EditText设置android:imeActionId属性,当触发此监听时根据id能判断时哪个触发的。
它还有一些其他用处,文档说明是

它还有一些其他用处,文档说明是

Set a special listener to be called when an action is performed on the text view. This will be called when the enter key is pressed, or when an action supplied to the IME is selected by the user. Setting this means that the normal hard key event will not insert a newline into the text view, even if it is multi-line; holding down the ALT modifier will, however, allow the user to insert a newline character.





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值