Android Question EditText And RequestFocus

Cüneyt Gargin

Member
Licensed User
Longtime User
I have a motorola device with barcode scanner..
I have an editbox to scan barcodes..
it scans and sends enter automatically...
I insert barcode into a database table...
Later on I clean editText with anEditText.Text =""
I call
anEditText.RequestFocus
(which is very important because user will scan hunderds of barcodes immediately and i cannot tell the user to click editbox to gain focus...)
and it does not gain Focus...


Please tell me a method to overcome this and please don't tell me you do not guarantee editText to gain focus(i.e. i read articles here)
 

Inman

Well-Known Member
Licensed User
Longtime User
If the barcode is read directly using a barcode scanner device (and not typed by user), why do you need an editbox to show it? You could display it using a label.
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
If the barcode is read directly using a barcode scanner device (and not typed by user), why do you need an editbox to show it? You could display it using a label.

I guess he is using the scanner in keyboard emulation mode (aka keyboard wedge mode).

In answer to the OP's question. My advice is to forget about using an editext. Read the integrator guide for your device and look at configuring Datawedge to use intents. It's a far better solution.
 
Upvote 0

Cüneyt Gargin

Member
Licensed User
Longtime User
I guess he is using the scanner in keyboard emulation mode (aka keyboard wedge mode).
That is my answer for Inman's question...
Yes it is in keyboard emulator mode..
Thanks keirS .. I will search for it...
If there is someone who has such an experience, can s/he help ?
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
Upvote 0

charlesg

Member
Licensed User
Longtime User
I have no problems with a no-name Android 2.3 barcode PDA. txtBarcode.requestfocus works fine for me.

In my experience the barcode field does indeed need to be edittext so that a value can be typed in when barcode fails to read.

I have had problems when more than one edittext on the same line. Is your barcode edittext on a line of its own?
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
Ok. Here is an outline of what you need to do:

On the TC55:

In Datawedge change your apps profile to:

Disable Keyboard Wedge Emulation
Enable Intent Output.
Set the intent action: use your apps package name and a description (yourpackagename.SCAN for example)
Set the intent category: I just use android.intent.DEFAULT
Set the intent delivery: You have a choice about which sort of Intent you want to use. I think the simplest to setup will be a broadcast intent.

In B4A you need to:

Download the BroadCastReciever library
Create a service to handle the intents broadcast by datawedge.
The instructions for the library are pretty straight forward. In the AddAction method you will just pass yourpackagename.SCAN.
 
Upvote 0

Cüneyt Gargin

Member
Licensed User
Longtime User
I have no problems with a no-name Android 2.3 barcode PDA. txtBarcode.requestfocus works fine for me.

In my experience the barcode field does indeed need to be edittext so that a value can be typed in when barcode fails to read.

I have had problems when more than one edittext on the same line. Is your barcode edittext on a line of its own?


what do you mean by saying "on the same line ????" .. I have a spinner, an editText and a Grid with a few buttons and labels on the Activity...

I cannot even focus on emulator....
 
Upvote 0

charlesg

Member
Licensed User
Longtime User
By 'on the same line' I meant views with the same top value. One of the things I miss in Android is the ability to set a tab order for views. I find this inability can lead to strange results when moving from one view to the next.

The following very simple app works on my pda. Does it work on yours?

I set up a layout 'layout1' with two edittexts, txtBarcode and txtDesc

B4X:
Sub Process_Globals
    Dim TIMER1 As Timer
End Sub

Sub Globals
    Dim txtBarcode As EditText
    Dim txtDesc As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
    TIMER1.Initialize("Timer1",1500)
    TIMER1.Enabled=False
    txtBarcode.Top=10
    txtDesc.Top=200
    Activity.Color=Colors.Cyan
    txtBarcode.RequestFocus
End Sub

Sub txtBarcode_EnterPressed()
    txtDesc.Text="Barcode Desc"
    TIMER1.Enabled=True
End Sub

Sub timer1_Tick()
    txtBarcode.Text=""
    txtDesc.Text=""
    txtBarcode.RequestFocus
    TIMER1.Enabled=False
End Sub
 
Upvote 0

Cüneyt Gargin

Member
Licensed User
Longtime User
When we use barcode scanner, it acts as if it is keyboard emulated. It writes barcode value to the textbox. You should write code to ENTER PRESSED (i.e. KEYPRESSED) or TEXTCHANGED event. to capture the event and barcode.
Cheers
 
Upvote 0

Federico956

Member
Licensed User
Longtime User
I try to explain my situation.
I have an EditText, when something is written in this EditText, there are two situations:
1) If the text was written manually, the user have to press "insert" button
2) If the text was scanned by the TC55's scanner, my app have to insert data automatically, calling "button_Click" event like if the button was really pressed

So,I can't use TEXTCHANGED, and I think that to do what I really need, I must use intent, right?
 
Upvote 0

Cüneyt Gargin

Member
Licensed User
Longtime User
No.
EditText has ENTERPRESSED event.. You should get ENTERPRESSED .. and should adjust TC55 to send ENTER after scan...

Sub editTextBarcode_EnterPressed
Dim docNo As String
Dim sqlStr As String
Dim cursor1 As Cursor
docNo =editTextBarcode.Text.SubString2(0,14)

sqlStr = "Select DocumentId From CargoDocuments Where CargoId ='" & docNo & "'"
cursor1 =Main.Sql1.ExecQuery(sqlStr)
Try
cursor1.Position =0
Main.RelatedDocumentID=cursor1.GetString("DocumentId")
Catch
Main.RelatedDocumentID = ""
If editTextBarcode.Text.Length < 24 OR editTextBarcode.Text.Length > 24 Then
Msgbox("Hatalı Barkod Okuttunuz..!!","HATA")
Else
Msgbox("Okutulan Barkod Size Zimmetli Değil.!!","HATA")
End If
refresherTimer.Enabled=True
Return

End Try
StartActivity("Delivery")
End Sub
 
Upvote 0

Cüneyt Gargin

Member
Licensed User
Longtime User
Ok. Here is an outline of what you need to do:

On the TC55:

In Datawedge change your apps profile to:

Disable Keyboard Wedge Emulation
Enable Intent Output.
Set the intent action: use your apps package name and a description (yourpackagename.SCAN for example)
Set the intent category: I just use android.intent.DEFAULT
Set the intent delivery: You have a choice about which sort of Intent you want to use. I think the simplest to setup will be a broadcast intent.

In B4A you need to:

Download the BroadCastReciever library
Create a service to handle the intents broadcast by datawedge.
The instructions for the library are pretty straight forward. In the AddAction method you will just pass yourpackagename.SCAN.
I Tried This Method. I adjusted device settings. But I could not write a service and call it.. Lets assume my packagename is scantest and SCAN is the method.
Can you please send me a sample code .. B.Regards...
 
Upvote 0

Cüneyt Gargin

Member
Licensed User
Longtime User
Ok. Here is an outline of what you need to do:

On the TC55:

In Datawedge change your apps profile to:

Disable Keyboard Wedge Emulation
Enable Intent Output.
Set the intent action: use your apps package name and a description (yourpackagename.SCAN for example)
Set the intent category: I just use android.intent.DEFAULT
Set the intent delivery: You have a choice about which sort of Intent you want to use. I think the simplest to setup will be a broadcast intent.

In B4A you need to:

Download the BroadCastReciever library
Create a service to handle the intents broadcast by datawedge.
The instructions for the library are pretty straight forward. In the AddAction method you will just pass yourpackagename.SCAN.

Ok. Here is an outline of what you need to do:

On the TC55:

In Datawedge change your apps profile to:

Disable Keyboard Wedge Emulation
Enable Intent Output.
Set the intent action: use your apps package name and a description (yourpackagename.SCAN for example)
Set the intent category: I just use android.intent.DEFAULT
Set the intent delivery: You have a choice about which sort of Intent you want to use. I think the simplest to setup will be a broadcast intent.

In B4A you need to:

Download the BroadCastReciever library
Create a service to handle the intents broadcast by datawedge.
The instructions for the library are pretty straight forward. In the AddAction method you will just pass yourpackagename.SCAN.
 

Attachments

  • ScanTest.zip
    504.3 KB · Views: 208
Upvote 0

Cüneyt Gargin

Member
Licensed User
Longtime User
I am trying broadcastReceiver library.. When I sendBroadcast from application with a menuItem, program enters into BroadcastReceiver_onReceive method.
However when I scan a barcode, the program does not enter into BroadcastReceiver_onReceive...
Does that mean my device does not broadcast an intent.. so I could not manage to adjust device to send intent...
 
Upvote 0
Top