当我单击“完成”时,Android OnEditorActionListener() actionId 给出 0
我已经创建了一个键盘。当用户输入数字时,它们会被发送到特定的 EditText
,但是当用户单击“完成”键时,它不会转到 setOnEditorActionListener
(但它会关闭键盘)。
这是我的代码:
final EditText txtQty = new EditText(this);
txtQty.setHeight(1);
txtQty.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 42));
txtQty.setInputType(InputType.TYPE_CLASS_PHONE);
txtQty.setImeOptions(EditorInfo.IME_ACTION_DONE);
txtQty.setSelectAllOnFocus(true);
txtQty.setTextSize(9);
txtQty.setVisibility(View.VISIBLE);
txtQty.setHint("0.0");
txtQty.setHighlightColor(R.color.green);
tr.addView(txtQty);
txtQty.setOnEditorActionListener( new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.i("KeyBoard" ,"Inside the Edit Text");
if (actionId == EditorInfo.IME_ACTION_DONE ||actionId == EditorInfo.IME_ACTION_NEXT ) { ......}
这里给出了 actionId = 0
和 EditorInfo.IME_ACTION_NEXT = 5
当我通过 Android 软键盘运行时,它工作正常。
txtQty.setOnEditorActionListener( new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.i("KeyBoard" ,"Inside the Edit Text");
Log.i("---EditorInfo.IME_ACTION_NEXT---" , EditorInfo.IME_ACTION_NEXT);
Log.i("---actionId---" , actionId);
Log.i("---event---" , event);
Log.i("---EditorInfo.IME_ACTION_DONE---" , EditorInfo.IME_ACTION_DONE);
这里给出了 EditorInfo.IME_ACTION_NEXT = 5, actionId = 5
和 EditorInfo.IME_ACTION_DONE = 6, actionId = 6
但是当我通过软键盘运行时,它给出了 EditorInfo .IME_ACTION_NEXT = 5, actionId = 0
和 EditorInfo.IME_ACTION_DONE = 6,actionId = 0
。
为什么它没有采用我的软键盘上的 actionId
值?
I have created a keyboard. When the user enters numbers they're sent to a particular EditText
, but when the user clicks on the "Done" key it doesn't go to setOnEditorActionListener
(but it does close the keyboard).
This is my code:
final EditText txtQty = new EditText(this);
txtQty.setHeight(1);
txtQty.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 42));
txtQty.setInputType(InputType.TYPE_CLASS_PHONE);
txtQty.setImeOptions(EditorInfo.IME_ACTION_DONE);
txtQty.setSelectAllOnFocus(true);
txtQty.setTextSize(9);
txtQty.setVisibility(View.VISIBLE);
txtQty.setHint("0.0");
txtQty.setHighlightColor(R.color.green);
tr.addView(txtQty);
txtQty.setOnEditorActionListener( new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.i("KeyBoard" ,"Inside the Edit Text");
if (actionId == EditorInfo.IME_ACTION_DONE ||actionId == EditorInfo.IME_ACTION_NEXT ) { ......}
Here it gives actionId = 0
and EditorInfo.IME_ACTION_NEXT = 5
When I run through the Android soft keyboard its working fine.
txtQty.setOnEditorActionListener( new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.i("KeyBoard" ,"Inside the Edit Text");
Log.i("---EditorInfo.IME_ACTION_NEXT---" , EditorInfo.IME_ACTION_NEXT);
Log.i("---actionId---" , actionId);
Log.i("---event---" , event);
Log.i("---EditorInfo.IME_ACTION_DONE---" , EditorInfo.IME_ACTION_DONE);
Here it's giving EditorInfo.IME_ACTION_NEXT = 5, actionId = 5
and EditorInfo.IME_ACTION_DONE = 6, actionId = 6
But when I run through my soft keyboard it gives EditorInfo.IME_ACTION_NEXT = 5,
and
actionId = 0EditorInfo.IME_ACTION_DONE = 6, actionId = 0
.
Why didn't it take the actionId
value on my soft keyboard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想获得actionid,请尝试以下方式:
在我的项目中,我像这样更改edittext的属性
,并在java文件中:
这样可以获得actionid = 6;
if you wanna got the actionid try this way:
in my project i change the edittext's properties like that
and in java file:
in this way could got the actionid = 6;