android 模拟输入框edittext控件按下回车或扫描头扫描到条码
edtScan.setText(result);
edtScan.onEditorAction(EditorInfo.IME_ACTION_NEXT);
场景:PDA都有扫描头,但有时想用自己的手机来扫码。于是给项目添加了相机使用Zbar识别二维码和条码的功能,
现在扫描头扫描到二维码或条码时是在PDA的扫描设置里加后缀(回车+换行)来实现输入框焦点跳转触发的。
相机识别二维码后需要模拟扫描头的扫描动作。不需要加回车换行,亲试无用,发现使用EditorInfo.IME_ACTION_NEXT,让输入框切换到下一个焦点即可。
edtScan.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { String scanertext = edtScan.getText().toString(); if (scanertext.contains("-") && scanertext.length() > 3) { edtScan.setText(""); RefreshWebView(scanertext); } else if (scanertext.length() > 0) { edtScan.setText(""); String msg = "编码规则不符,请扫描位置二维码!"; Toast.makeText(HtmlViewActivity.this, msg, Toast.LENGTH_SHORT).show(); MainActivity.getInstance().SpeakVoice(msg); String head = "<head>" + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\"> " + "<style>html{padding:15px;} body{word-wrap:break-word;font-size:13px;padding:0px;margin:0px} p{padding:0px;margin:0px;font-size:13px;color:#222222;line-height:1.3;} img{padding:0px,margin:0px;max-width:100%; width:auto; height:auto;}</style>" + "</head>"; webview.loadData("<html>" + head + "<body>" + " <h1>请扫描位置二维码!eg:A-R1:C1</h1> " + "</body></html>", "text/html;charset=utf-8", "utf-8"); } return true; } }); }
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
"作者:" 数据酷软件工作室
"出处:" http://datacool.cnblogs.com
"专注于CMS(综合赋码系统),MES,WCS(智能仓储设备控制系统),WMS,商超,桑拿、餐饮、客房、足浴等行业收银系统的开发,15年+从业经验。因为专业,所以出色。"
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
"作者:" 数据酷软件工作室
"出处:" http://datacool.cnblogs.com
"专注于CMS(综合赋码系统),MES,WCS(智能仓储设备控制系统),WMS,商超,桑拿、餐饮、客房、足浴等行业收银系统的开发,15年+从业经验。因为专业,所以出色。"
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++