【发布时间】:2020-04-04 08:10:38
【问题描述】:
我正在为 PDA 设备编写条码扫描器应用程序。在该设备中,只有 LF 终结器。所以当我扫描条形码时,光标跳到了另一行。即使我设置了edittext.requestFocus(),光标也不会回到编辑文本的开头。我想将光标回调到第一行并定位“0”。我怎样才能做到这一点?另一件事是,我可以获得按下的触发键码吗?这是代码-
ID.setOnKeyListener(View.OnKeyListener { _, keyCode, event ->
if (event.keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_DOWN ) {
if (edt_location.text.toString() == "" || edt_qty.text.toString() == "") {
Toast.makeText(this, "Make Sure To Enter Location And Qty", Toast.LENGTH_SHORT)
.show()
edt_id.setText("")
} else{
try {
val item=Item(
edt_id.text.toString(),
Integer.parseInt(edt_qty.text.toString()),
edt_location.text.toString()
)
qt=edt_qty.text.toString().toInt()
record_code=edt_id.text.toString()
record_location=edt_location.text.toString()
db.addItem(item)
db.viewData()
txt_article.setText(code.toString())
txt_price.setText(price.toString())
txt_description.setText(desc.toString())
txt_isbn.setText(record_code.toString())
txt_tran_qty.setText(qty.toString())
record_id=edt_id.text.toString()
edt_id.setText("")
edt_id.requestFocus()
} catch (nfe: NumberFormatException) {
nfe.printStackTrace()
}
}
}
false
})
【问题讨论】:
标签: android kotlin keypress barcode-scanner keycode