Android Question Tabhost stealing focus (Lollipop)

rbw152

Member
Licensed User
Longtime User
Hi all,

Hope you can help me.

I have a TabHost which contains a ScrollView which contains a single EditText control.
Then, I have a single EditText underneath, just on the form itself.

When using a Bluetooth scanner to scan a barcode into the form's EditText, the TabHost seems to steal the focus resulting in the barcode being entered into the Scrollview EditText.

I have no idea why this is happening, but it seems to work fine on my JellyBean tablet. Hope I'm not making a rookie mistake here.

I have attached the test project I've been using to attempt to replicate this.

Many thanks in advance!
 

Attachments

  • testProject.zip
    7.8 KB · Views: 234

Informatix

Expert
Licensed User
Longtime User
It's a known bug of TabHost.

In Explorer.bas of my File Explorer class, I added this comment:
'If your activity contains a TabHost, add these lines before the call to Explorer:
' Dim r As Reflector
' r.Target = TabHost1
' r.RunMethod2("setDescendantFocusability", 0x00060000, "java.lang.int") 'FOCUS_BLOCK_DESCENDANTS
'And these lines after:
' r.RunMethod2("setDescendantFocusability", 0x00040000, "java.lang.int") 'FOCUS_AFTER_DESCENDANTS
' TabHost1.RequestFocus
'That will prevent the TabHost from stealing the focus (a known bug, still not fixed in Android 4.0.3).

Hope that helps.
 
Upvote 0

rbw152

Member
Licensed User
Longtime User
Thanks for your replies.

Erel, the tab-changed event doesn't seem to be triggered when the bluetooth scan happens or when the focus is put into the scrollview. Only when switching between tabs.

Informatix, yeah that code seems to work. But I have no idea where to put it, since the focus is stolen when the barcode scanner does it's scan. I'm not technically calling anything when the problem occurs.

And I'm not using the serial/asyncstreams to connect via bluetooth since the scanners seem to pair/connect fine on their own. I can't get the Serial to connect to these scanners anyway, but that's a different problem for another thread.
 
Last edited:
Upvote 0
Top