Android Question Button does not function inside the panel

herryj

Member
Licensed User
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Initialize Scale
    'Scale.SetRate(0.5)
    'Activity.LoadLayout("Menu")
    'Activity.Width = 100%x
    'Activity.Height = 100%y
   
    pnlMenu.Initialize("")
    Activity.AddView(pnlMenu,0dip,0dip,100%x,100%y)
    pnlMenu.SetBackgroundImage(LoadBitmap(File.DirAssets,"menu.png"))
   
    'play button
   
    btnPlay.Initialize("button_play")
    btnPlay.Text="Herry"
   
    pnlMenu.AddView(btnPlay,0,0,50%x,70%y)
    'btnPlay.Bitmap=LoadBitmap(File.DirAssets,"playbutton.png")
    'btnPlay.BringToFront
    'Activity.AddView(btnPlay,50%x - 80%x / 2, 50%y - 40%y / 2, 80%x, 40%y)
   
    'Scale.VerticalCenter2(pnlMenu, imgPlay,pnlMenu)
    'btnPlay.SetBackgroundImage(LoadBitmap(File.DirAssets,"playbutton.png"))
    'Scale.ScaleView(imgPlay)
   
    CREATE_SLIDE_MENU
End Sub
Sub button_play_click
    ToastMessageShow("you rocked the world!!!, yeah",True)
End Sub
I've followed the example given in this Post http://www.b4x.com/android/forum/threads/how-does-one-add-a-button-to-a-panel-in-code.25628/

Though still it doesn't work.
Whats wrong with this.

Thanks for the help in advance.
 

klaus

Expert
Licensed User
This code works:
B4X:
Sub Globals
    Dim pnlMenu As Panel
    Dim btnPlay As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    pnlMenu.Initialize("")
    Activity.AddView(pnlMenu,0dip,0dip,100%x,100%y)
'    pnlMenu.SetBackgroundImage(LoadBitmap(File.DirAssets,"menu.png"))
    btnPlay.Initialize("button_play")
    btnPlay.Text="Herry"
    pnlMenu.AddView(btnPlay,0,0,50%x,70%y)
End Sub

Sub button_play_click
    ToastMessageShow("you rocked the world!!!, yeah",True)
End Sub
So the problem must be somewhere else.
What are you doing in CREATE_SLIDE_MENU ?

I would suggest you to use "btnPlay" for the generic event name instead of "button_play".
And then Sub btnPlay_Click, the code would better readable.
 

herryj

Member
Licensed User
Hi klaus, I've already change "button_play" to "btnplay", but still it doesn't work.

When I swipe the right side of "pnlMenu" it shows another menu. Here is the code of CREATE_SLIDE_MENU


B4X:
Sub CREATE_SLIDE_MENU
    sldMenu.Initialize("Drawer", pnlMenu, (pnlMenu.Width-100dip))
    sldMenu.SetEdgeSize(sldMenu.GRAVITY_START,sldMenu.GetEdgeSize(sldMenu.GRAVITY_START) * 3)
    'btn sound
    btnSound.Initialize("button_sound")
    btnSound.SetBackgroundImage(LoadBitmap(File.DirAssets,"btnsound.png"))
    'btn Music
    btnMusic.Initialize("button_music")
    btnMusic.SetBackgroundImage(LoadBitmap(File.DirAssets,"btnmusic.png"))
    'view
    sldMenu.NavigationPanel.AddView(btnSound,50%x - 80%x / 2,70%y - 50%y / 2,(pnlMenu.Width-130%x),(pnlMenu.Height-250%y))
    sldMenu.NavigationPanel.AddView(btnMusic,110%x - 170%x / 2,70%y - 50%y / 2,(pnlMenu.Width-130%x),(pnlMenu.Height-250%y))
    sldMenu.NavigationPanel.SetBackgroundImage(LoadBitmap(File.DirAssets,"slidemenu.png"))
   
    'sldMenu.NavigationPanel.Color = Colors.RGB(209,151,35)
End Sub
 

herryj

Member
Licensed User
Hi Klaus

here is the project attached
and image showing the error.

thanks for your help.

menu.png slidemenu.png
 

Attachments

klaus

Expert
Licensed User
This code works:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    'display panel
    pnlMenu.Initialize("")
    Activity.AddView(pnlMenu,0dip,0dip,100%x,100%y)
    pnlMenu.SetBackgroundImage(LoadBitmap(File.DirAssets,"menu.png"))
   
    CREATE_SLIDE_MENU

    'play button
    btnPlay.Initialize("btnplay")
    btnPlay.Text = "Herry"
    pnlMenu.AddView(btnPlay,50%x - 80%x / 2, 50%y - 40%y / 2, 80%x, 40%y)
   
'    CREATE_SLIDE_MENU
End Sub
 

herryj

Member
Licensed User
Hi klaus

problem fixed, I just need to put the button in CREATE_SLIDE_MENU, and used ContentPanel property.

well, thanks anyway for your help and time. ;)
 
Top