我需要检测 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 中的按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!