Android Question 'Next' Key Behaviour

RichardN

Well-Known Member
Licensed User
Longtime User
I have an input dialog panel with 8 EditText child views that pops up full-screen over the top of a main activity panel which also has several of it's own child EditText views.

When the panel is made visible the topmost EditText has focus.
Touch 'next' and focus goes logically down to the next EditText.
Touch 'next' again and the focus disappears from view.
Touch 'next' again and the focus returns to the next logical position.

Following experimentation it appears that the focus is falling to EditText views that are out of sight behind the visible panel. To make matters worse these views are accepting input if the user types blindly.

This is very illogical..... Is it a bug ? Do I have to disable all hidden views to prevent them from gaining focus ? Will making the main program panel invisible fix this behaviour ?
 

RichardN

Well-Known Member
Licensed User
Longtime User
Hi Klaus,

No not at all.... After much troubleshooting I can state with some certainty...

Managing views by grouping them onto a panel (full-screen or otherwise) is good programming practice however....
ANY views on any panel where panel.visible = True will be included in the TabOrder facilitated by the 'Next' key, even if that panel is obscured from the user. Effectively the 'Next' key does not know what the user can see and what he cannot, it only knows which views are set to visible and will tab around those views moving focus from absolute top-left to bottom-right. Consequently key-stokes may end up in very unexpected places.

If, like me, you are in the habit of using a panelMain to hold the first/primary interface then you are going to have to set panelMain.visibilty = False when you pop up another panel over the top of it. Otherwise the tab order will be completely illogical.

This will be a difficult concept for those of us still trying to wash the last memories of MS programming environments out of our heads!
 
Upvote 0

ivan.tellez

Active Member
Licensed User
Longtime User
This will be a difficult concept for those of us still trying to wash the last memories of MS programming environments out of our heads!

NOT actually.

What you are doing its like put lots of TextFields in a single window/form, make the TabIndex random, and just expect that magically the compiler know what you whant and fix your UI for you.


This is very illogical..... Is it a bug ? Do I have to disable all hidden views to prevent them from gaining focus ? Will making the main program panel invisible fix this behaviour ?

Actually its the most logical behavior if you dont asign the "tab index" the views will have a random behavior. Its simple, If you dont whant a view to gain focus, you have to Hide it, or at least, his parent view.




The "Tab order", its the zOrder. In the designer its the order of the view's list on the left of the window
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
ivan.tellez said:
The "Tab order", its the zOrder. In the designer its the order of the view's list on the left of the window

That is incorrect. It has nothing to do with zOrder. The way the OS handles tab order between views is activity relative position top to bottom and left to right, diagonally.

The 'form' metaphor from MS-VS simply does not read across to Android development so I will have to disagree with you... as I suspect will many others. This is not a B4A issue but an aspect of the way the OS handles tab-order that is not immediately obvious to the newcomer and is sure to cause some scratching of heads! ANY 'visible' view can accept focus... not just the ones you can see.

Top tip!.....

If you are using panels to contain full-screen interfaces make sure to set any other panel behind it as hidden to avoid this issue.
 
Last edited:
Upvote 0

ivan.tellez

Active Member
Licensed User
Longtime User
the list is in alphabetical order.

Shure! ;)

Now I realize that the z comes before the a in alalphabetical order LOL
 

Attachments

  • zorder.jpg
    zorder.jpg
    88.9 KB · Views: 257
Last edited:
Upvote 0

ivan.tellez

Active Member
Licensed User
Longtime User
That is incorrect. It has nothing to do with zOrder. The way the OS handles tab order between views is activity relative position top to bottom and left to right, diagonally.

That is incorrect.

I did not say that this was the OS behavior.

The way the OS handles tab order between views is actually done in the XML where the views are defined. ITS NOT allways top to bottom and left to right, diagonally. So, if you made your app in java an create the layoust in a text editor, you can have complete conntrol about the "tab order" (nextFocusDown, nextFocusLeft, nextFocusRight, nextFocusUp)

BUT in B4A you have not this control, so the better practice is to make your layouts in the bstract designer, with the correct zOrdering to let the compiler create the XML with the tab order you expected.


ANY 'visible' view can accept focus... not just the ones you can see.

Shure, this is really clear for newcomers. Any view in the activity which visible property is set to TRUE, can receive focus, no matter if its on screen or not.

If you are using panels to contain full-screen interfaces make sure to set any other panel behind it as hidden to avoid this issue.

There is not a hidden property. (Again, not clear for newcomers)

The correct tip is Set the visible property to TRUE, of all the panels you want to exclude from gaining focus (all the chlid views will be excluded as well)

Example code

B4X:
Sub ChangePage(Page As Int)
    pnlPage1.Visible = False
    pnlPage2.Visible = False
    pnlPage3.Visible = False
    pnlPage4.Visible = False

    Select Case Page
        Case 1
            pnlPage1.Visible = True
        Case 2
            pnlPage2.Visible = True
        Case 3
            pnlPage3.Visible = True
        Case 4
            pnlPage4.Visible = True
    End Select
End Sub
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
You could also use the Parent keyword to set all the child views Enable=False so tha they dont acept the focus.. a disabled view does not catch the focus
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
@ ivan.tellez

I have reproduced your project depicted in your .jpg above. When you run it the tab order does not follow the designer 'zOrder' sequence you suggest....

Can you offer an explanation ?
 

Attachments

  • FocusDemo.zip
    7.4 KB · Views: 138
Upvote 0
Top