如何将按键代码转换为字符或字符串?
如何将keycode
转换为char
或string
?
这里是示例代码:
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
//Log.d("EditText", "It's Working...!" + event.getAction());
if (event.getAction() == 0) {
switch (v.getId()) {
case R.id.editText1:
Log.d("EditText", "In editText1");
if (text1.length() == 3)
{
text2.setText();
text2.requestFocus();
}
break;
case R.id.editText2:
Log.d("EditText", "In editText2");
if (text2.length() == 0)
text1.requestFocus();
break;
}
}
return false;
}
How to convert the keycode
into char
or string
??
Here is the example code:
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
//Log.d("EditText", "It's Working...!" + event.getAction());
if (event.getAction() == 0) {
switch (v.getId()) {
case R.id.editText1:
Log.d("EditText", "In editText1");
if (text1.length() == 3)
{
text2.setText();
text2.requestFocus();
}
break;
case R.id.editText2:
Log.d("EditText", "In editText2");
if (text2.length() == 0)
text1.requestFocus();
break;
}
}
return false;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
使用
event.getNumber()
。Use
event.getNumber()
.如果您没有 KeyEvent 对象,您可以在键码上使用它:
If you don't have a KeyEvent object you can use this on the keycode :
Tod 的答案几乎已经完成,但是当您想使用此事件代码设置编辑文本的文本时,您应该添加一些东西:
Tod answer is almost complete, but when you want to settext of an edittext with this eventcode you should to add a little thing:
如果您想将一个按键从一个控件发送到另一个控件(例如,从
RecylerView
到其中的EditText
),您可以使用 这个:If you want to send a key from one control to another (for instance, from
RecylerView
toEditText
inside it), you can use this:试试这个..
Try this..
使用
String.fromCharCode(65,66,67)
返回ABC
。请参阅 https://developer.mozilla.org/ en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode 。
Use
String.fromCharCode(65,66,67)
returnsABC
.See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode .