How to know key presses in EditText(如何知道 EditText 中的按键)
问题描述
我需要检测 EditText 中软键盘或硬键盘上的每个按键.我只需要在按下字符时一次发送一个字符,不需要最终的文本字符串.
I need to detect every key press on either a soft or hard keyboard in EditText. I just need to send the characters one at a time as they are pressed and don't need the final text string.
我曾尝试将 EditText 与 onKeyPress 一起使用,但我在这里遇到了问题,即无法使用软键盘和 TextWatcher 进行按键操作不是一个好的选择,因为我需要每个按键.是否有任何解决方案可以知道所有按键(包括返回、移位、回车...也)?
I have tried using an EditText with onKeyPress, but I ran into the problems here with not getting key presses with soft keyboards and TextWatcher isn't a good option because I need each key press.
Is there any solution to know all the keypresses (including back, shift, enter... also)?
推荐答案
如果你有一个EditText,那么你可以使用TextWatcher接口.在我的代码中,search_edit 是一个 EditText.
If you have an EditText, then you can use the TextWatcher interface. In my code, search_edit is an EditText.
search_edit.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//here is your code
myadapter.getFilter().filter(s);
listview.setAdapter(myadapter);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
这篇关于如何知道 EditText 中的按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何知道 EditText 中的按键
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
