Android Question creating UI not based on the designer objects

zohar

Member
Licensed User
Longtime User
Hi

what are the preferred ways to create customized UI ?
for example , ive attached a picture of snakes and ladders .
suppose i want to create my menus with the same layout , so each cell represent a button and will be clickable .
for example pressing on 25 will do x and pressing on 40 will do y .

thanks in advance .
 

Attachments

  • snakes.jpeg
    snakes.jpeg
    48.2 KB · Views: 304

zohar

Member
Licensed User
Longtime User
Hi .

Thanks for the tip it works .
ive created image object and add few labels .
the code below show 2 clicks's subs which call show_count .


how to change the code below to work with array (lblapple = Array As Label(apple1, apple2, apple3, apple4, apple5))
so each time i click the button, show_count will change the label to disable and i will be able to check the order of the clicks (apple1 first , apple2 second etc ..)



Sub show_count
countlabels=countlabels+1
If countlabels=4 Then
Msgbox("Finished","Great")
MediaPlayer1.Initialize( )
MediaPlayer1.Load(File.DirAssets, "einav.mp3")
MediaPlayer1.Play
End If
End Sub


Sub apple1_Click
show_count
apple1.Enabled=False
End Sub


Sub apple2_Click
show_count
apple2.Enabled=False
End Sub


Sub apple3_click
..
..
..

Thanks ,
Zohar
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Please use code tags

I am not sure I understood what you want but you might want to use sender keyword
All lables should have the same event name and you add only one sub like
B4X:
Sub apple_Click
    dim s as label = Sender
    s.Enabled=False
   ....

End sub
 
Upvote 0

zohar

Member
Licensed User
Longtime User
Please use code tags

I am not sure I understood what you want but you might want to use sender keyword
All lables should have the same event name and you add only one sub like
B4X:
Sub apple_Click
    dim s as label = Sender
    s.Enabled=False
   ....

End sub
thanks for the quick reply
but what i actually want is to be able to manipulate the label attribute from different SUB.
this way all the logic will be outside the apple_Click .
in pseudo code :
click on label -> call other sub which will verify if the label can be clicked now --> do something --> disable the label so it cannot be clicked.

this routine should be run for multiple labels , and i want to centralized my code as much as possible .
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Are your labels global ?
You should be able to manipulate views from any sub if you declare them inside Sub Globals
 
Upvote 0

zohar

Member
Licensed User
Longtime User
Are your labels global ?
You should be able to manipulate views from any sub if you declare them inside Sub Globals
Hi

I have global varaible still i can't understand how to pass the information the other sub .

here is a code example :
and i still can't understand , when i click on apple1_click how to pass to show_count that i press on label apple1 .
i want that show_count will be aware to which label clicked , so if i press apple1/apple2/apple3 show_count will be able to manipulate the label .

B4X:
Sub Globals
            Private apple1 As Label
        Private apple2 As Label
        Private apple3 As Label
        Private apple4 As Label
        Private apple5 As Label
        Dim countlabels As Int   
        countlabels=0  
End Sub



Sub apple1_Click
         show_count
        apple1.Enabled=False
End Sub


Sub show_count
    countlabels=countlabels+1
    If countlabels=4 Then
        Msgbox("Finished","Great")
        MediaPlayer1.Initialize( )
   MediaPlayer1.Load(File.DirAssets, "einav.mp3")
    MediaPlayer1.Play
    End If   
    End Sub
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Maybe
B4X:
Sub apple1_Click
        dim l as label=sender
         show_count(l)
        apple1.Enabled=False
End Sub
B4X:
sub show_count (sendr as label)
    'sendr is the clicked label
    
end sub
 
Upvote 0

zohar

Member
Licensed User
Longtime User
Maybe
B4X:
Sub apple1_Click
        dim l as label=sender
         show_count(l)
        apple1.Enabled=False
End Sub
B4X:
sub show_count (sendr as label)
    'sendr is the clicked label
 
end sub

Great , this example work .
i was able to run :
B4X:
sub show_count (sendr as label)
    sendr.enabled=false
 
end sub

however , i still need to configure click function for each label ?
this function only send label apple1 and it is not respond to other labels .
is there a way that whatever label i choose will run with one click function and send the relevant label which was clicked ?
so for example , the following code will be able to react and send each label that i press :

B4X:
Sub general_Click
        dim l as label=sender
         show_count(l)
End Sub

Thanks ,
Zohar
 
Upvote 0

zohar

Member
Licensed User
Longtime User
You should set the same Event Name to all the labels (doing it using the Designer or, if you create them by code, passing the name initializing them)
View attachment 44041

one little question :
how do i get the label name from the sender ?
B4X:
sub show_count (sendr As Label)
     sendr.enabled=False
    Msgbox(sendr.[somthing],"label name")
    End If
 
Upvote 0
Top