gpt4 book ai didi

Android OnEditorActionListener() actionId 在我单击“完成”时给出 0

转载 作者:行者123 更新时间:2023-11-29 18:16:46 24 4
gpt4 key购买 nike

我已经创建了一个键盘。当用户输入数字时,它们会被发送到特定的 EditText,但是当用户单击“Done”键时,它不会转到 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 = 0EditorInfo.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 = 5EditorInfo.IME_ACTION_DONE = 6, actionId = 6

但是当我运行我的软键盘时,它给出 EditorInfo.IME_ACTION_NEXT = 5,
actionId = 0
EditorInfo.IME_ACTION_DONE = 6, actionId = 0

为什么它没有在我的软键盘上获取 actionId 值?

最佳答案

如果你想得到 actionid 试试这个方法:

在我的项目中,我像那样更改编辑文本的属性

input type  -----  text
ime options ----- actionDone

在 java 文件中:

  etSearch = (EditText) findViewById(R.id.etSearch);
etSearch.setOnEditorActionListener(mEditorActionListener);

private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// TODO Auto-generated method stub
if (actionId == EditorInfo.IME_ACTION_DONE) {
//do something
}
return false;
}
};

这样就可以得到actionid = 6;

关于Android OnEditorActionListener() actionId 在我单击“完成”时给出 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7663239/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com