我已经创建了一个键盘。当用户输入数字时,它们将被发送到特定的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
值? 最佳答案
如果您想获取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;