我想创建 android 条码扫描器并显示来自 SQL 数据库的查询结果。可以使用查看按钮检索结果:
btnview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if((edtproname.getText().toString().length()==28)&&(edtproname.getText() !=null))
try {
PreparedStatement statement = connect.prepareStatement("EXEC viewProduct '"+edtproname.getText().toString()+"'");
String location = edtproname.getText().subSequence(20,28).toString();
edtlocation.setText(location);
rs = statement.executeQuery();
while (rs.next()) {
edtproname.setText(rs.getString("ProName"));
edtprodesc.setText(rs.getString("ProDesc"));
}
} catch (SQLException e) {
Toast.makeText(AddProducts.this, e.getMessage(),
Toast.LENGTH_LONG).show();
}
edtqty.requestFocus();
InputMethodManager manager= (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
manager.showSoftInput(edtqty, InputMethodManager.SHOW_FORCED);
}
这是条形码读取事件:
@Override
public void onBarcodeEvent(final BarcodeReadEvent event){
runOnUiThread(new Runnable() {
@Override
public void run() {
String barcodeData = event.getBarcodeData();
//String timestamp = event.getTimestamp();
edtproname.setText(""+barcodeData);
}
如何在扫描仪结果加载后自动显示?没有查看按钮?如何直接使用硬件触发显示结果?
感谢您的帮助...谢谢。
图片:示例应用程序