当我单击“完成”时,Android OnEditorActionListener()actionId为0
我已经创建了一个键盘。当用户输入数字时,它们会被发送到特定的当我单击“完成”时,Android OnEditorActionListener()actionId为0,android,android-emulator,keyboard,Android,Android Emulator,Keyboard,我已经创建了一个键盘。当用户输入数字时,它们会被发送到特定的EditText,但当用户单击“完成”键时,它不会进入setOnEditorActionListener(但它会关闭键盘) 这是我的代码: final EditText txtQty = new EditText(this); txtQty.setHeight(1); txtQty.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 42));
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\u ACTION\u 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\u ACTION\u NEXT=5,actionId=5
和EditorInfo.IME\u ACTION\u DONE=6,actionId=6
但当我用我的软键盘运行时,它给出了EditorInfo.IME\u ACTION\u NEXT=5,
actionId=0
和EditorInfo.IME\u ACTION\u DONE=6,actionId=0
为什么不在我的软键盘上输入actionId值?如果您想获得actionId,请尝试以下方法: 在我的项目中,我这样更改edittext的属性
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