Android 如何将光标回调到EditText中的第1行和位置0?
我正在为PDA设备编写条形码扫描仪应用程序。在这个设备中只有LF终端。因此,当我扫描条形码时,光标跳到另一行。即使我设置了Android 如何将光标回调到EditText中的第1行和位置0?,android,kotlin,keypress,barcode-scanner,keycode,Android,Kotlin,Keypress,Barcode Scanner,Keycode,我正在为PDA设备编写条形码扫描仪应用程序。在这个设备中只有LF终端。因此,当我扫描条形码时,光标跳到另一行。即使我设置了edittext.requestFocus()光标也不会回到编辑文本的开头。我想将光标调回第一行并定位“0”。我该怎么做?另一件事是,我能得到按下的触发键代码吗?这是密码- ID.setOnKeyListener(View.OnKeyListener { _, keyCode, event -> if (event.keyCode == KeyEven
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
})
因此,关于这个问题的解决方案,我认为您的问题的解决方案应该非常简单:
edt_id.setSelection(position)
whereposition是您所需的光标位置
你的密码到底是什么