Android Question Managing object Panel

Nitin Joshi

Active Member
Licensed User
Longtime User
Hi, My APP includes several Panels around 50. I have Named panels as P01, P2, P03......
I want to make visibility True/False based on input Panel number by user. I remember, VB6 has index numbering. I would like to use similarly in my APP.
 
If they are added to the activity in the correct order and there is nothing else in the root of the activity i.e. they are in order in the Views Tree Tab in the designer, then you can access them via Activity.GetView(Index).

If they are not in order or there are other views in the root, then you will need to build your own index.

I would store it in an Array of Panels which you can then access by index.
 
Upvote 0
If you add a number to the Tag for each panel in the designer, starting from 0 in the order you want them you can bulid the index like this:

Code: Copy
For Each V As View In Activity.GetAllViewsRecursive
        If V Is Panel And V.Tag <> "" Then
            Panels(V.Tag) = V
        End If
    Next

Where Panels is a global array of panels
Code: Copy
Dim Panels(50) As Panel

Then Do
Code: Copy
Panels(3).Visible = False
 
Upvote 0
By the way... Where do I mention below code?

Code: Copy
For Each V As View In Activity.GetAllViewsRecursive
        If V Is Panel And V.Tag <> "" Then
            Panels(V.Tag) = V
        End If
    Next
 
Upvote 0
I tried this code. No error in compiling however when APP is opened, it floats the error and APP gets close.

Error
java.lang.RuntimeException: Object should first be initialized (Panel).

I have assigned in array in sub Globals
 
Upvote 0
Have you put the code After you have loaded the layout?
Code: Copy
    'Load layout then

    For Each V As View In Activity.GetAllViewsRecursive
        If V Is Panel And V.Tag <> "" Then
            Panels(V.Tag) = V
        End If
    Next
 
Upvote 0
I have written this code as below

Code: Copy
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("My_Layout")
    For Each V As View In Activity.GetAllViewsRecursive
        If V Is Panel And V.Tag <> "" Then
            Panels(V.Tag) = V
        End If
    Next
End Sub
 
Upvote 0
Try putting it at the end of the Activity_Create Sub with a Sleep(0) before it.
Code: Copy
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("My_Layout")

'Any other code 






    Sleep(0)
    For Each V As View In Activity.GetAllViewsRecursive
        If V Is Panel And V.Tag <> "" Then
            Panels(V.Tag) = V
        End If
    Next
End Sub
 
Upvote 0
Still problem continues. Let me tell you more about my project. My APP is interacting with ESP8266. I am executing panel visibility code in UDP_PacketArrived Sub. Please refer below code

Please feel free to ask more details...

Code: Copy
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("My_Layout")
    UDP_Skt.Initialize("UDP",4211,255)
    Sleep (0)
    For Each V As View In Activity.GetAllViewsRecursive
        If V Is Panel And V.Tag <> "" Then
            Panels(V.Tag) = V
        End If
    Next
End Sub

Sub UDP_PacketArrived (Pkt As UDPPacket)
    Dim pnl As Int
    UDPRcvMsg = BytesToString(Pkt.Data, Pkt.Offset, Pkt.Length,"UTF8")
 If UDPRcvMsg.Length>=13 And UDPRcvMsg.SubString2(0,10)="SetControl" Then
     pnl=UDPRcvMsg.SubString2(10,13) 'Here I get panel number to make visible
     If UDPRcvMsg.SubString(13)="1" Then 'if last char of received string is 1 then panel should be visible.
            Panels(pnl).Visible=True
        Else
            Panels(pnl).Visible=False
        End If
    End If
   
End Sub
 
Upvote 0
As I said in post #5, add a number to the tag field in the designer for each Panel in the order you want then to be in the Array, starting at 0. The looped code then gets the tag and puts the a reference to the pane in the correct index of the Panels array.
 
Upvote 0
total panels on my designer are 11. I assigned Dim Panels(10) as Panels however APP threw error. Later I changed to Dim Panels (11) as Panels and it worked.

So If I include one more Panel then I must change the array number?
 
Upvote 0
Back
Top