0

I am writing barcode scanner app for PDA device. In this device there is only LF terminator. So When I scan the barcode, the cursor jumped to another line.Even thought I set edittext.requestFocus() the cursor will not come back to the start of the edit text. I would like to call back the cursor to the first line and position"0". How can I do that? And another thing is , Can I get the pressed trigger keycode? Here is the code -

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

    })
kinesis
  • 203
  • 1
  • 2
  • 11

1 Answers1

0

So regarding the solution to this question I assume the solution to your problem should be quite easy:

edt_id.setSelection(position)

whereposition is your desired cursor position.

What exactely is your keycode?